enhance: zoom in shouldn't update the collapse status in db/files

This commit is contained in:
Tienson Qin
2021-12-27 11:09:42 +08:00
committed by Andelf
parent 1cff06f347
commit cd9bb9190f
3 changed files with 108 additions and 108 deletions

View File

@@ -3566,3 +3566,31 @@
(save-block! (state/get-current-repo)
(:block/uuid block)
content))))
(defn block-default-collapsed?
"Whether a block should be collapsed by default.
Currently, this handles several cases:
1. Zoom in mode, it will open the current block if it's collapsed.
2. Queries.
3. References."
[block config]
(let [collapsed? (cond
(and (:block? config)
(= (:id config) (str (:block/uuid block))))
false
(and (:block? config)
(get-in block [:block/properties :collapsed]))
true
:else
(boolean
(and
(seq (:block/children block))
(or (:custom-query? config)
(and (:ref? config)
(>= (:ref/level block)
(state/get-ref-open-blocks-level)))))))]
(if (or (:ref? config) (:block? config))
collapsed?
(get-in block [:block/properties :collapsed]))))