瀏覽代碼

enhance: only sort selection blocks when mouse up

Tienson Qin 4 年之前
父節點
當前提交
76f2e514e2
共有 2 個文件被更改,包括 15 次插入6 次删除
  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]
    :on-mouse-over (fn [e]
                     (block-mouse-over e has-child? *control-show? block-id doc-mode?))
                     (block-mouse-over e has-child? *control-show? block-id doc-mode?))
    :on-mouse-leave (fn [e]
    :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
 (defn- build-refs-data-value
   [block refs]
   [block refs]

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

@@ -551,11 +551,18 @@
    (set-selection-blocks! blocks :down))
    (set-selection-blocks! blocks :down))
   ([blocks direction]
   ([blocks direction]
    (when (seq blocks)
    (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!
 (defn into-selection-mode!
   []
   []