Browse Source

enhance: search jump add blocks to selection

Weihua Lu 4 years ago
parent
commit
84b5f97270

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

@@ -909,21 +909,12 @@
        (set-block-property! block-id "id" (str block-id))))
    (util/copy-to-clipboard! (tap-clipboard block-id))))
 
-(defn exit-editing-and-set-selected-blocks!
-  ([blocks]
-   (exit-editing-and-set-selected-blocks! blocks :down))
-  ([blocks direction]
-   (util/clear-selection!)
-   (state/clear-edit!)
-   (state/set-selection-blocks! blocks direction)
-   (util/select-highlight! blocks)))
-
 (defn select-block!
   [block-uuid]
   (when-let [block (-> (str block-uuid)
                        (js/document.getElementsByClassName)
                        first)]
-    (exit-editing-and-set-selected-blocks! [block])))
+    (state/exit-editing-and-set-selected-blocks! [block])))
 
 (defn select-all-blocks!
   []
@@ -931,7 +922,7 @@
     (let [input (gdom/getElement current-input-id)
           blocks-container (util/rec-get-blocks-container input)
           blocks (dom/by-class blocks-container "ls-block")]
-      (exit-editing-and-set-selected-blocks! blocks))))
+      (state/exit-editing-and-set-selected-blocks! blocks))))
 
 (defn- get-selected-blocks-with-children
   []
@@ -1183,7 +1174,7 @@
           blocks (if (= :up direction)
                    (reverse blocks)
                    blocks)]
-      (exit-editing-and-set-selected-blocks! blocks direction))))
+      (state/exit-editing-and-set-selected-blocks! blocks direction))))
 
 (defn on-select-block
   [direction]
@@ -1191,7 +1182,7 @@
     (cond
       ;; when editing, quit editing and select current block
       (state/editing?)
-      (exit-editing-and-set-selected-blocks! [(gdom/getElement (state/get-editing-block-dom-id))])
+      (state/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/selection?) (== 1 (count (state/get-selection-blocks))))
@@ -2109,7 +2100,7 @@
                    (f))]
     (when block
       (.scrollIntoView block #js {:behavior "smooth" :block "center"})
-      (exit-editing-and-set-selected-blocks! [block]))))
+      (state/exit-editing-and-set-selected-blocks! [block]))))
 
 (defn- select-up-down [direction]
   (let [selected (first (state/get-selection-blocks))
@@ -2120,7 +2111,7 @@
     (when (and sibling-block (dom/attr sibling-block "blockid"))
       (clear-selection! nil)
       (.scrollIntoView sibling-block #js {:behavior "smooth" :block "center"})
-      (exit-editing-and-set-selected-blocks! [sibling-block]))))
+      (state/exit-editing-and-set-selected-blocks! [sibling-block]))))
 
 (defn- move-cross-boundrary-up-down
   [direction]

+ 1 - 10
src/main/frontend/handler/ui.cljs

@@ -78,22 +78,13 @@
       (let [elements (array-seq (js/document.getElementsByClassName id))]
         (when (first elements)
           (util/scroll-to-element (gobj/get (first elements) "id")))
-        (doseq [element elements]
-          (dom/add-class! element "block-highlight")
-          (js/setTimeout #(dom/remove-class! element "block-highlight")
-                         4000)))
+        (state/exit-editing-and-set-selected-blocks! elements))
       (when-let [element (gdom/getElement fragment)]
         (util/scroll-to-element fragment)
         (dom/add-class! element "block-highlight")
         (js/setTimeout #(dom/remove-class! element "block-highlight")
                        4000)))))
 
-(defn scroll-and-highlight!
-  [state]
-  (if-let [fragment (util/get-fragment)]
-    (highlight-element! fragment))
-  state)
-
 (defn add-style-if-exists!
   []
   (when-let [style (or

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

@@ -1295,3 +1295,12 @@
 (defn get-editor-cp
   []
   (get-in @state [:view/components :editor]))
+
+(defn exit-editing-and-set-selected-blocks!
+  ([blocks]
+   (exit-editing-and-set-selected-blocks! blocks :down))
+  ([blocks direction]
+   (util/clear-selection!)
+   (clear-edit!)
+   (set-selection-blocks! blocks direction)
+   (util/select-highlight! blocks)))

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

@@ -359,21 +359,6 @@
    (defn stop [e]
      (when e (doto e (.preventDefault) (.stopPropagation)))))
 
-#?(:cljs
-   (defn get-fragment
-     []
-     (when-let [hash js/window.location.hash]
-       (when (> (count hash) 2)
-         (-> (subs hash 1)
-             (string/split #"\?")
-             (first))))))
-
-#?(:cljs
-   (defn fragment-with-anchor
-     [anchor]
-     (let [fragment (get-fragment)]
-       (str "#" fragment "?anchor=" anchor))))
-
 (def speed 500)
 (def moving-frequency 15)