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

fix(ux): multiple selection for reading mode

charlie 3 лет назад
Родитель
Сommit
f1463a40ab

+ 8 - 2
src/main/frontend/components/block.cljs

@@ -1808,7 +1808,9 @@
                 (f)
                 (js/setTimeout f 5))
 
-              (when block-id (state/set-selection-start-block! block-id)))))))))
+              (when block-id
+                (state/set-selection-start-block! block-id)
+                (state/set-state! :selection/pending? true)))))))))
 
 (rum/defc dnd-separator-wrapper < rum/reactive
   [block block-id slide? top? block-content?]
@@ -1883,7 +1885,11 @@
                                     (not (string/includes? content "```"))
                                     (not (gobj/get e "shiftKey")))
                                ;; clear highlighted text
-                               (util/clear-selection!)))}
+                               (util/clear-selection!))
+
+                             ;; yield for other micro tasks
+                             (js/setTimeout
+                               #(state/set-state! :selection/pending? false) 32))}
        (not slide?)
        (merge attrs))
 

+ 2 - 1
src/main/frontend/components/sidebar.cljs

@@ -447,7 +447,8 @@
 (defn- hide-context-menu-and-clear-selection
   [e]
   (state/hide-custom-context-menu!)
-  (when-not (gobj/get e "shiftKey")
+  (when (and (not (state/selection-pending?))
+             (not (gobj/get e "shiftKey")))
     (editor-handler/clear-selection!)))
 
 (rum/defcs ^:large-vars/cleanup-todo sidebar <

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

@@ -131,6 +131,7 @@
      :db/persisted?                         {}
      :cursor-range                          nil
 
+     :selection/pending?                    false
      :selection/mode                        false
      :selection/blocks                      []
      :selection/start-block                 nil
@@ -684,6 +685,10 @@
   []
   (:selection/mode @state))
 
+(defn selection-pending?
+  []
+  (:selection/pending? @state))
+
 (defn selection?
   "True sense of selection mode with valid selected block"
   []