瀏覽代碼

fix: block selection when there're page/block embeds

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

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

@@ -2821,9 +2821,7 @@
 
 (rum/defcs ^:large-vars/cleanup-todo block-container-inner < rum/reactive db-mixins/query
   {:init (fn [state]
-           (assoc state ::ref (or (:*ref (second (:rum/args state)))
-                                  (atom nil))))
-
+           (assoc state ::ref (or (:*ref (second (:rum/args state))) (atom nil))))
    :did-mount (fn [state]
                 (when-let [editing-node @(:editor/editing @state/state)]
                   (let [ref @(::ref state)

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

@@ -297,7 +297,9 @@
       :history/page-only-mode?               false
       ;; db tx-id -> editor cursor
       :history/tx->editor-cursor             (atom {})
-      :system/info                           {}})))
+      :system/info                           {}
+      ;; Whether block is selected
+      :ui/select-query-cache                 (atom {})})))
 
 ;; Block ast state
 ;; ===============
@@ -672,10 +674,17 @@ Similar to re-frame subscriptions"
 
 (defn sub-block-selected?
   [block-uuid]
-  (rum/react
-   (rum/derived-atom [(:selection/blocks @state)] [::select-block block-uuid]
-     (fn [s]
-       (contains? (set (get-selected-block-ids s)) block-uuid)))))
+  (let [*cache (:ui/select-query-cache @state)
+        keys [::select-block block-uuid]
+        atom (or (get @*cache keys)
+                 (let [result (rum/derived-atom
+                               [(:selection/blocks @state)]
+                               keys
+                               (fn [s]
+                                 (contains? (set (get-selected-block-ids s)) block-uuid)))]
+                   (swap! *cache assoc keys result)
+                   result))]
+    (rum/react atom)))
 
 (defn block-content-max-length
   [repo]
@@ -1247,7 +1256,8 @@ Similar to re-frame subscriptions"
   (swap! state merge {:cursor-range    nil
                       :editor/last-saved-cursor nil})
   (set-state! :editor/content {})
-  (set-state! :editor/block nil))
+  (set-state! :editor/block nil)
+  (set-state! :ui/select-query-cache {}))
 
 (defn into-code-editor-mode!
   []