fix(editor): pasted template had chaotic orders

This commit is contained in:
rcmerci
2021-05-10 20:43:19 +08:00
parent a2d35f6208
commit 4d2c5f05a6
2 changed files with 23 additions and 2 deletions

View File

@@ -1862,8 +1862,13 @@
block-uuid (:block/uuid block)
including-parent? (not (false? (:including-parent (:block/properties block))))
blocks (if including-parent? (db/get-block-and-children repo block-uuid) (db/get-block-children repo block-uuid))
level-blocks-map (blocks-with-level blocks)
tree (blocks-vec->tree (vals level-blocks-map))]
level-blocks (vals (blocks-with-level blocks))
grouped-blocks (group-by #(= db-id (:db/id %)) level-blocks)
root-block (or (first (get grouped-blocks true)) (assoc (db/pull db-id) :level 0))
blocks-exclude-root (get grouped-blocks false)
sorted-blocks (tree/sort-blocks blocks-exclude-root root-block)
result-blocks (if including-parent? sorted-blocks (drop 1 sorted-blocks))
tree (blocks-vec->tree result-blocks)]
(paste-block-tree-at-point tree [:template :including-parent]
(fn [content]
(->> content