Skip to content

Commit

Permalink
fix(outliner): fix delete nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
defclass committed Apr 30, 2021
1 parent 31f8638 commit 972dfee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,10 @@
blocks (reorder-blocks blocks)]
(let [start-node (outliner-core/block (first blocks))
end-node (get-top-level-end-node blocks)]
(outliner-core/delete-nodes start-node end-node lookup-refs)
(let [opts {:key :block/change
:data blocks}]
(db/refresh! repo opts))))))
(when (outliner-core/delete-nodes start-node end-node lookup-refs)
(let [opts {:key :block/change
:data blocks}]
(db/refresh! repo opts)))))))

(defn- block-property-aux!
[block-id key value]
Expand Down
38 changes: 21 additions & 17 deletions src/main/frontend/modules/outliner/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -393,23 +393,27 @@
[start-node end-node block-ids]
{:pre [(tree/satisfied-inode? start-node)
(tree/satisfied-inode? end-node)]}
(ds/auto-transact!
[txs-state (ds/new-outliner-txs-state)] {:outliner-op :delete-nodes}
(if (= start-node end-node)
(delete-node start-node)
(let [right-node (tree/-get-right end-node)
end-node-left-nodes (get-left-nodes end-node (count block-ids))
start-node-parents-with-self (conj (get-node-parents start-node 1000) (tree/-get-id start-node))]
(when (tree/satisfied-inode? right-node)
(let [cross-node-id (first (set/intersection (set end-node-left-nodes) (set start-node-parents-with-self)))
cross-node (get-block-by-id cross-node-id)
new-left-id (if (= cross-node start-node)
(tree/-get-left-id cross-node)
cross-node-id)
new-right-node (tree/-set-left-id right-node new-left-id)]
(tree/-save new-right-node txs-state)))
(let [txs (db-outliner/del-blocks block-ids)]
(ds/add-txs txs-state txs))))))
(let [sibling? (= (tree/-get-parent-id start-node)
(tree/-get-parent-id end-node))]
(when sibling?
(ds/auto-transact!
[txs-state (ds/new-outliner-txs-state)]
{:outliner-op :delete-nodes}
(if (= start-node end-node)
(delete-node start-node)
(let [right-node (tree/-get-right end-node)
end-node-left-nodes (get-left-nodes end-node (count block-ids))
start-node-parents-with-self (conj (get-node-parents start-node 1000) (tree/-get-id start-node))]
(when (tree/satisfied-inode? right-node)
(let [cross-node-id (first (set/intersection (set end-node-left-nodes) (set start-node-parents-with-self)))
cross-node (get-block-by-id cross-node-id)
new-left-id (if (= cross-node start-node)
(tree/-get-left-id cross-node)
cross-node-id)
new-right-node (tree/-set-left-id right-node new-left-id)]
(tree/-save new-right-node txs-state)))
(let [txs (db-outliner/del-blocks block-ids)]
(ds/add-txs txs-state txs))))))))

(defn first-child?
[node]
Expand Down

0 comments on commit 972dfee

Please sign in to comment.