Просмотр исходного кода

fix: always clear selection before set selected blocks

Weihua Lu 4 лет назад
Родитель
Сommit
59a8eca650

+ 2 - 7
src/main/frontend/handler/editor.cljs

@@ -191,9 +191,7 @@
 
 (defn clear-selection!
   [_e]
-  (doseq [block (dom/by-class "selected")]
-    (dom/remove-class! block "selected")
-    (dom/remove-class! block "noselect"))
+  (util/select-unhighlight! (dom/by-class "selected"))
   (state/clear-selection!))
 
 (defn- text-range-by-lst-fst-line [content [direction pos]]
@@ -1149,8 +1147,7 @@
 (defn clear-last-selected-block!
   []
   (let [block (state/drop-last-selection-block!)]
-    (dom/remove-class! block "selected")
-    (dom/remove-class! block "noselect")))
+    (util/select-unhighlight! [block])))
 
 (defn input-start-or-end?
   ([input]
@@ -1167,7 +1164,6 @@
 (defn highlight-selection-area!
   [end-block]
   (when-let [start-block (state/get-selection-start-block)]
-    (clear-selection! nil)
     (let [blocks (util/get-nodes-between-two-nodes start-block end-block "ls-block")
           direction (util/get-direction-between-two-nodes start-block end-block "ls-block")
 
@@ -2154,7 +2150,6 @@
             :down util/get-next-block-non-collapsed)
         sibling-block (f selected)]
     (when (and sibling-block (dom/attr sibling-block "blockid"))
-      (clear-selection! nil)
       (.scrollIntoView sibling-block #js {:behavior "smooth" :block "center"})
       (state/exit-editing-and-set-selected-blocks! [sibling-block]))))
 

+ 2 - 0
src/main/frontend/state.cljs

@@ -1320,6 +1320,8 @@
    (exit-editing-and-set-selected-blocks! blocks :down))
   ([blocks direction]
    (util/clear-selection!)
+   (util/select-unhighlight! (dom/by-class "selected"))
+   (clear-selection!)
    (clear-edit!)
    (set-selection-blocks! blocks direction)
    (util/select-highlight! blocks)))

+ 6 - 0
src/main/frontend/util.cljc

@@ -1155,6 +1155,12 @@
      (doseq [block blocks]
        (d/add-class! block "selected noselect"))))
 
+#?(:cljs
+   (defn select-unhighlight!
+     [blocks]
+     (doseq [block blocks]
+       (d/remove-class! block "selected" "noselect"))))
+
 (defn keyname [key] (str (namespace key) "/" (name key)))
 
 (defn batch [in max-time idle? handler]