瀏覽代碼

fix: don't clear selection in blocks

Tienson Qin 2 年之前
父節點
當前提交
db7bc72a3c
共有 3 個文件被更改,包括 17 次插入11 次删除
  1. 1 1
      src/main/frontend/components/block.cljs
  2. 8 4
      src/main/frontend/components/sidebar.cljs
  3. 8 6
      src/main/frontend/state.cljs

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

@@ -2147,7 +2147,7 @@
         (do
           (util/stop e)
           (state/conj-selection-block! (gdom/getElement block-id) :down)
-          (when (and block-id (not (state/get-selection-start-block)))
+          (when block-id
             (state/set-selection-start-block! block-id)))
         (when (contains? #{1 0} button)
           (when-not (target-forbidden-edit? target)

+ 8 - 4
src/main/frontend/components/sidebar.cljs

@@ -536,10 +536,14 @@
 (defn- hide-context-menu-and-clear-selection
   [e]
   (state/hide-custom-context-menu!)
-  (when-not (or (gobj/get e "shiftKey")
-                (util/meta-key? e)
-                (state/get-edit-input-id))
-    (editor-handler/clear-selection!)))
+  (let [block (.closest (.-target e) ".ls-block")]
+    (when-not (or (gobj/get e "shiftKey")
+                  (util/meta-key? e)
+                  (state/get-edit-input-id)
+                  (and block
+                       (or (= block (.-target e))
+                           (.contains block (.-target e)))))
+      (editor-handler/clear-selection!))))
 
 (rum/defc render-custom-context-menu
   [links position]

+ 8 - 6
src/main/frontend/state.cljs

@@ -914,14 +914,15 @@ Similar to re-frame subscriptions"
   (when-let [input (get-input)]
     (util/get-selection-start input)))
 
-(defn set-selection-start-block!
-  [start-block]
-  (swap! state assoc :selection/start-block start-block))
-
 (defn get-selection-start-block
   []
   (get @state :selection/start-block))
 
+(defn set-selection-start-block!
+  [start-block]
+  (when-not (get-selection-start-block)
+    (swap! state assoc :selection/start-block start-block)))
+
 (defn set-selection-blocks!
   ([blocks]
    (set-selection-blocks! blocks :down))
@@ -942,7 +943,8 @@ Similar to re-frame subscriptions"
   (swap! state assoc
          :selection/mode false
          :selection/blocks nil
-         :selection/direction :down))
+         :selection/direction :down
+         :selection/start-block nil))
 
 (defn get-selection-blocks
   []
@@ -1963,4 +1965,4 @@ Similar to re-frame subscriptions"
 (defn get-icloud-container-root-url
   []
   (when (mobile-util/native-ios?)
-    (get-in @state [:mobile/container-urls :iCloudContainerUrl])))
+    (get-in @state [:mobile/container-urls :iCloudContainerUrl])))