소스 검색

refactor: selection state

Weihua Lu 4 년 전
부모
커밋
d05c540c15
3개의 변경된 파일12개의 추가작업 그리고 8개의 파일을 삭제
  1. 1 2
      src/main/frontend/components/content.cljs
  2. 6 6
      src/main/frontend/handler/editor.cljs
  3. 5 0
      src/main/frontend/state.cljs

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

@@ -268,8 +268,7 @@
                                               :left (str client-x "px")
                                               :top (str (+ scroll-y client-y) "px")))))
 
-                          (and (state/in-selection-mode?)
-                               (seq (state/get-selection-blocks)))
+                          (state/selection?)
                           (do
                             (util/stop e)
                             (let [client-x (gobj/get e "clientX")

+ 6 - 6
src/main/frontend/handler/editor.cljs

@@ -1082,21 +1082,21 @@
       (exit-editing-and-set-selected-blocks! [(gdom/getElement (state/get-editing-block-dom-id))])
 
       ;; when selection and one block selected, select next block
-      (and (state/in-selection-mode?) (== 1 (count (state/get-selection-blocks))))
+      (and (state/selection?) (== 1 (count (state/get-selection-blocks))))
       (let [f (if (= :up direction) util/get-prev-block util/get-next-block)
             element (f (first (state/get-selection-blocks)))]
         (when element
           (state/conj-selection-block! element direction)))
 
       ;; if same direction, keep conj on same direction
-      (and (state/in-selection-mode?) (= direction (state/get-selection-direction)))
+      (and (state/selection?) (= direction (state/get-selection-direction)))
       (let [f (if (= :up direction) util/get-prev-block util/get-next-block)
             element (f (last (state/get-selection-blocks)))]
         (when element
           (state/conj-selection-block! element direction)))
 
       ;; if different direction, keep clear until one left
-      (state/in-selection-mode?)
+      (state/selection?)
       (clear-last-selected-block!))))
 
 (defn save-block-aux!
@@ -2384,7 +2384,7 @@
   * when in edit mode with text selected, copy selected text as normal"
   [e]
   (cond
-    (and (state/in-selection-mode?) (seq (state/get-selection-blocks)))
+    (state/selection?)
     (shortcut-copy-selection e)
 
     (state/editing?)
@@ -2404,7 +2404,7 @@
   [state-fn]
   (fn [e]
     (cond
-      (and (state/in-selection-mode?) (seq (state/get-selection-blocks)))
+      (state/selection?)
       (shortcut-cut-selection e)
 
       (state/editing?)
@@ -2414,7 +2414,7 @@
   [state-fn]
   (fn [e]
     (cond
-      (and (state/in-selection-mode?) (seq (state/get-selection-blocks)))
+      (state/selection?)
       (shortcut-delete-selection e)
 
       (state/editing?)

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

@@ -549,6 +549,11 @@
   []
   (:selection/mode @state))
 
+(defn selection?
+  "True sense of selection mode with valid selected block"
+  []
+  (and (in-selection-mode?) (seq (get-selection-blocks))))
+
 (defn conj-selection-block!
   [block direction]
   (dom/add-class! block "selected noselect")