mirror of https://github.com/logseq/logseq
feat: add toggle open
parent
5446c17f58
commit
a19e336371
|
@ -3028,17 +3028,31 @@
|
|||
(doseq [{:block/keys [uuid]} blocks-to-collapse]
|
||||
(collapse-block! uuid)))))))))
|
||||
|
||||
(defn collapse-all!
|
||||
(defn- collapse-all!
|
||||
[]
|
||||
(let [blocks-with-level
|
||||
(all-blocks-with-level {:collapse? true})
|
||||
level 1]
|
||||
(let [blocks-to-collapse
|
||||
(->> blocks-with-level
|
||||
(filter (fn [b] (= (:block/level b) level)))
|
||||
(remove (fn [b]
|
||||
(or (not (db-model/has-children? (:block/uuid b)))
|
||||
(-> b :block/properties :collapsed)))))]
|
||||
(when (seq blocks-to-collapse)
|
||||
(doseq [{:block/keys [uuid]} blocks-to-collapse]
|
||||
(collapse-block! uuid))))))
|
||||
(let [blocks-to-collapse
|
||||
(->> (all-blocks-with-level {:collapse? true})
|
||||
(filter (fn [b] (= (:block/level b) 1)))
|
||||
(remove (fn [b] (-> b :block/properties :collapsed))))]
|
||||
(when (seq blocks-to-collapse)
|
||||
(doseq [{:block/keys [uuid]} blocks-to-collapse]
|
||||
(collapse-block! uuid)))))
|
||||
|
||||
(defn- expand-all!
|
||||
[]
|
||||
(->> (all-blocks-with-level {})
|
||||
(filter (fn [b] (-> b :block/properties :collapsed)))
|
||||
(map (comp expand-block! :block/uuid))
|
||||
doall))
|
||||
|
||||
(defn toggle-open! []
|
||||
(let [all-collapsed?
|
||||
(->> (all-blocks-with-level {:collapse? true})
|
||||
(filter (fn [b] (= (:block/level b) 1)))
|
||||
(every? (fn [{:block/keys [uuid properties]}]
|
||||
(or
|
||||
(not (db-model/has-children? uuid))
|
||||
(some? (-> properties :collapsed))))))]
|
||||
(if all-collapsed?
|
||||
(expand-all!)
|
||||
(collapse-all!))))
|
||||
|
|
|
@ -195,10 +195,6 @@
|
|||
{:desc "Collapse"
|
||||
:binding "mod+up"
|
||||
:fn editor-handler/collapse!}
|
||||
:editor/collapse-top-blocks
|
||||
{:desc "Collapse all blocks"
|
||||
:binding "mod+shift+l"
|
||||
:fn editor-handler/collapse-all!}
|
||||
:editor/indent
|
||||
{:desc "Indent block"
|
||||
:binding "tab"
|
||||
|
@ -304,6 +300,10 @@
|
|||
{:desc "Toggle wide mode"
|
||||
:binding "t w"
|
||||
:fn ui-handler/toggle-wide-mode!}
|
||||
:editor/toggle-open-blocks
|
||||
{:desc "Toggle open blocks, either collapse or expand all blocks"
|
||||
:binding "t o"
|
||||
:fn editor-handler/toggle-open!}
|
||||
;; :ui/toggle-between-page-and-file route-handler/toggle-between-page-and-file!
|
||||
:git/commit
|
||||
{:desc "Git commit message"
|
||||
|
@ -319,7 +319,6 @@
|
|||
:editor/new-line
|
||||
:editor/indent
|
||||
:editor/outdent
|
||||
:editor/collapse-top-blocks
|
||||
:editor/collapse-block-children
|
||||
:editor/expand-block-children
|
||||
:go/search
|
||||
|
@ -330,6 +329,7 @@
|
|||
:editor/zoom-out
|
||||
:editor/copy
|
||||
:editor/cut
|
||||
:editor/toggle-open-blocks
|
||||
:ui/toggle-wide-mode]
|
||||
|
||||
:shortcut.category/formatting
|
||||
|
@ -387,6 +387,7 @@
|
|||
^{:doc "Toggle"}
|
||||
[:ui/toggle-help
|
||||
:ui/toggle-new-block
|
||||
:editor/toggle-open-blocks
|
||||
:ui/toggle-wide-mode
|
||||
:ui/toggle-document-mode
|
||||
:ui/toggle-brackets
|
||||
|
|
|
@ -44,8 +44,6 @@
|
|||
:shortcut.category/others "其他"
|
||||
:shortcut.ui/toggle-wide-mode "切换宽屏模式"
|
||||
:shortcut.ui/toggle-brackets "切换是否显示括号"
|
||||
:shortcut.ui/fold "折叠块(非编辑状态)"
|
||||
:shortcut.ui/un-fold "展开块(非编辑状态)"
|
||||
:shortcut.search/re-index "重新建立搜索索引"
|
||||
:shortcut.graph/re-index "重新建立图库索引"
|
||||
:shortcut.editor/bold "粗体"
|
||||
|
@ -73,7 +71,8 @@
|
|||
:shortcut.editor/forward-kill-word "向后删除一个单词"
|
||||
:shortcut.editor/backward-kill-word "向前删除一个单词"
|
||||
:shortcut.editor/open-edit "编辑选中块"
|
||||
:shortcut.editor/delete-selection "删除选中块"}
|
||||
:shortcut.editor/delete-selection "删除选中块"
|
||||
:shortcut.editor/toggle-open-blocks "切换折叠/展开所有块(非编辑g状态"}
|
||||
:zh-Hant
|
||||
{:shortcut.editor/indent "縮進塊標簽"
|
||||
:shortcut.editor/outdent "取消縮進塊"
|
||||
|
|
Loading…
Reference in New Issue