Browse Source

enhance: only sort selection blocks when mouse up

Tienson Qin 4 years ago
parent
commit
76f2e514e2
2 changed files with 15 additions and 6 deletions
  1. 3 1
      src/main/frontend/components/block.cljs
  2. 12 5
      src/main/frontend/state.cljs

+ 3 - 1
src/main/frontend/components/block.cljs

@@ -1743,7 +1743,9 @@
    :on-mouse-over (fn [e]
                     (block-mouse-over e has-child? *control-show? block-id doc-mode?))
    :on-mouse-leave (fn [e]
-                     (block-mouse-leave e has-child? *control-show? block-id doc-mode?))})
+                     (block-mouse-leave e has-child? *control-show? block-id doc-mode?))
+   :on-mouse-up (fn [e]
+                  (state/sort-selection-blocks!))})
 
 (defn- build-refs-data-value
   [block refs]

+ 12 - 5
src/main/frontend/state.cljs

@@ -551,11 +551,18 @@
    (set-selection-blocks! blocks :down))
   ([blocks direction]
    (when (seq blocks)
-     (let [blocks (util/sort-by-height blocks)]
-       (swap! state assoc
-             :selection/mode true
-             :selection/blocks blocks
-             :selection/direction direction)))))
+     (swap! state assoc
+            :selection/mode true
+            :selection/blocks blocks
+            :selection/direction direction))))
+
+(defn sort-selection-blocks!
+  []
+  (when (:selection/mode @state)
+    (swap! state update :selection/blocks
+           (fn [blocks]
+             (when (seq blocks)
+               (util/sort-by-height blocks))))))
 
 (defn into-selection-mode!
   []