fix: slow input cursor for the new created block

pull/10438/head
Tienson Qin 2023-09-11 17:27:55 +08:00
parent 9d8d20792e
commit bc9c3b4506
2 changed files with 11 additions and 29 deletions

View File

@ -3433,9 +3433,11 @@
(rum/defcs block-item < rum/reactive
{:init (fn [state]
(let [id (random-uuid)
editing-block (state/get-edit-block)
current-block (second (:rum/args state))
disable-lazy? (:disable-lazy-load? (first (:rum/args state)))
*ref (atom nil)
*hidden? (if disable-lazy?
*hidden? (if (or disable-lazy? (= (:block/uuid editing-block) (:block/uuid current-block)))
(atom false)
(get-hidden-atom id *ref {:initial-value true}))]
(assoc state ::sub-id id ::ref *ref ::hidden? *hidden?)))

View File

@ -366,37 +366,17 @@ independent of format as format specific heading characters are stripped"
(when-let [page (db-utils/entity [:block/name (util/safe-page-name-sanity-lc page)])]
(:block/properties page)))
;; FIXME: alert
(defn sort-by-left
([blocks parent]
(sort-by-left blocks parent {:check? true}))
([blocks parent {:keys [check?]}]
(let [blocks (util/distinct-by :db/id blocks)]
(when (and check?
;; Top-level blocks on whiteboards have no relationships of :block/left
(not= "whiteboard" (:block/type (db-utils/entity (:db/id parent)))))
(when (not= (count blocks) (count (set (map :block/left blocks))))
(let [duplicates (->> (map (comp :db/id :block/left) blocks)
frequencies
(filter (fn [[_k v]] (> v 1)))
(map (fn [[k _v]]
(let [left (db-utils/pull k)]
{:left left
:duplicates (->>
(filter (fn [block]
(= k (:db/id (:block/left block))))
blocks)
(map #(select-keys % [:db/id :block/level :block/content :block/file])))}))))]
(util/pprint duplicates)))
;; (assert (= (count blocks) (count (set (map :block/left blocks)))) "Each block should have a different left node")
)
(let [left->blocks (reduce (fn [acc b] (assoc acc (:db/id (:block/left b)) b)) {} blocks)]
(loop [block parent
result []]
(if-let [next (get left->blocks (:db/id block))]
(recur next (conj result next))
(vec result)))))))
([blocks parent {:keys [_check?]}]
(let [blocks (util/distinct-by :db/id blocks)
left->blocks (reduce (fn [acc b] (assoc acc (:db/id (:block/left b)) b)) {} blocks)]
(loop [block parent
result []]
(if-let [next (get left->blocks (:db/id block))]
(recur next (conj result next))
(vec result))))))
(defn try-sort-by-left
[blocks parent]