doc: add outliner core docs

pull/1698/head
defclass 2021-04-29 15:29:08 +08:00
parent d45982536f
commit a7b83af0f4
1 changed files with 24 additions and 20 deletions

View File

@ -233,7 +233,6 @@
(swap! blocks-atom concat result))
(first result)))))
(defn- walk-&-insert-nodes
[loc target-node sibling?]
(let [update-node-fn
@ -332,28 +331,33 @@
result))))
(defn delete-nodes
"Delete nodes from the tree, start-node and end-node must be siblings."
"Delete nodes from the tree, start-node and end-node must be siblings.
Args:
start-node: the node at the top of the outliner document.
end-node: the node at the bottom of the outliner document
block-ids: block ids between the start node and end node, including all the
children.
"
[start-node end-node block-ids]
{:pre [(tree/satisfied-inode? start-node)
(tree/satisfied-inode? end-node)]}
(do (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)
conn (conn/get-conn false)
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)))))))
(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]