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

This commit is contained in:
Tienson Qin
2023-10-11 00:03:17 +08:00
parent bc422b1718
commit d4420bed82
2 changed files with 17 additions and 9 deletions

View File

@@ -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)

View File

@@ -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!
[]