瀏覽代碼

fix: page hangs when embeding the parent block

Closed #1119
Tienson Qin 5 年之前
父節點
當前提交
bf13349fc1
共有 2 個文件被更改,包括 14 次插入9 次删除
  1. 2 1
      src/main/frontend/components/editor.cljs
  2. 12 8
      src/main/frontend/handler/editor.cljs

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

@@ -141,12 +141,13 @@
       (when input
         (let [current-pos (:pos (util/get-caret-pos input))
               edit-content (state/sub [:editor/content id])
+              edit-block (state/get-edit-block)
               q (or
                  @editor-handler/*selected-text
                  (when (> (count edit-content) current-pos)
                    (subs edit-content pos current-pos)))
               matched-blocks (when-not (string/blank? q)
-                               (editor-handler/get-matched-blocks q))
+                               (editor-handler/get-matched-blocks q (:block/uuid edit-block)))
               chosen-handler (fn [chosen _click?]
                                (state/set-editor-show-block-search! false)
                                (let [uuid-string (str (:block/uuid chosen))]

+ 12 - 8
src/main/frontend/handler/editor.cljs

@@ -609,10 +609,10 @@
              ;; fix editing template with multiple headings
              (when (> (count blocks) 1)
                (let [new-value (-> (text/remove-level-spaces (:block/content (first blocks)) (:block/format (first blocks)))
-                                  (string/trim-newline))
-                    edit-input-id (state/get-edit-input-id)]
-                (when edit-input-id
-                  (state/set-edit-content! edit-input-id new-value))))
+                                   (string/trim-newline))
+                     edit-input-id (state/get-edit-input-id)]
+                 (when edit-input-id
+                   (state/set-edit-content! edit-input-id new-value))))
 
              (when (or (seq retract-refs) pre-block?)
                (ui-handler/re-render-root!))
@@ -1736,13 +1736,17 @@
         pages))))
 
 (defn get-matched-blocks
-  [q]
+  [q block-id]
   ;; remove current block
-  (let [current-block (state/get-edit-block)]
+  (let [current-block (state/get-edit-block)
+        block-parents (set (->> (db/get-block-parents (state/get-current-repo)
+                                                      block-id
+                                                      99)
+                                (map (comp str :block/uuid))))
+        current-and-parents (set/union #{(str (:block/uuid current-block))} block-parents)]
     (remove
      (fn [h]
-       (= (:block/uuid current-block)
-          (:block/uuid h)))
+       (contains? current-and-parents (:block/uuid h)))
      (search/search q 10))))
 
 (defn get-matched-templates