fix: selection for virtualized blocks

This commit is contained in:
Tienson Qin
2024-07-25 21:35:40 +08:00
parent 5c8190e5e4
commit 0eaf10cacc
3 changed files with 58 additions and 36 deletions

View File

@@ -1229,27 +1229,34 @@
(delete-block-aux! block))))
(defn highlight-selection-area!
[end-block & {:keys [append?]}]
[end-block-id & {:keys [append?]}]
(when-let [start-block (state/get-selection-start-block-or-first)]
(let [node (gdom/getElement start-block)
selected-blocks (state/get-selection-blocks)
latest-visible-block (or node
(when-let [node (first selected-blocks)]
(.-id ^js node))
(when-let [node (last selected-blocks)]
(.-id ^js node)))]
(let [end-block-node (gdom/getElement end-block-id)
node (gdom/getElement start-block)
select-direction (state/get-selection-direction)
visible? (and node (util/el-visible-in-viewport? node))
selected-blocks (state/get-unsorted-selection-blocks)
last-node (when-let [node (last selected-blocks)]
(when-let [node (gdom/getElement (.-id ^js node))]
(when (util/el-visible-in-viewport? node)
node)))
latest-visible-block (or last-node (when visible? node))
latest-block-id (when latest-visible-block (.-id latest-visible-block))]
(when latest-visible-block
(let [blocks (util/get-nodes-between-two-nodes latest-visible-block end-block "ls-block")
direction (util/get-direction-between-two-nodes latest-visible-block end-block "ls-block")
blocks (if (= :up direction)
(reverse blocks)
blocks)]
(let [blocks (util/get-nodes-between-two-nodes latest-block-id end-block-id "ls-block")
direction (if (= latest-block-id end-block-id)
select-direction
(util/get-direction-between-two-nodes latest-block-id end-block-id "ls-block"))
blocks (if (= direction :up)
(reverse (util/sort-by-height blocks))
(util/sort-by-height blocks))]
(if append?
(do (state/clear-edit!)
(state/conj-selection-block! blocks direction))
(if (and select-direction (not= direction select-direction))
(state/drop-selection-blocks-starts-with! end-block-node)
(state/conj-selection-block! blocks direction)))
(state/exit-editing-and-set-selected-blocks! blocks direction)))))))
(defn- select-block-up-down
[direction]
(cond