An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Support folding sibling mind map branches with Alt click https://github.com/siyuan-note/siyuan/issues/19716
Danield3b5694d6de5
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.syindex 83744d9e84..fd6b7380ec 100644--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy@@ -8,7 +8,7 @@"title": "Formatting elements","title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;","type": "doc",- "updated": "20261002002136"+ "updated": "20261003225941"},"Children": [{@@ -1911,7 +1911,7 @@"HeadingLevel": 2,"Properties": {"id": "20210104091509-v1x69oc",- "updated": "20260928143000"+ "updated": "20261003225941"},"Children": [{@@ -1934,6 +1934,38 @@}]},+ {+ "ID": "20261003225941-mxlfdrn",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20261003225941-mxlfdrn",+ "updated": "20261003225941"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "Hold "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Alt"+ },+ {+ "Type": "NodeText",+ "Data": " ("+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "⌥"+ },+ {+ "Type": "NodeText",+ "Data": " on macOS) and click a node's fold button to fold or expand sibling branches under the same parent. If any sibling branch is expanded, all are folded; otherwise, all are expanded. Deeper folding states are preserved. A normal click only toggles the current node."+ }+ ]+ },{"ID": "20210104091509-ilh76fd","Type": "NodeMindmap",diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.syindex 323ed7a95b..e5db15a42f 100644--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy@@ -7,7 +7,7 @@"id": "20200924100950-9op5xi1","title": "Shortcuts","type": "doc",- "updated": "20261002230606"+ "updated": "20261003225941"},"Children": [{@@ -12884,7 +12884,7 @@"Type": "NodeHeading","Properties": {"id": "20260921105011-4zeuyl4",- "updated": "20261001015635"+ "updated": "20261003225941"},"HeadingLevel": 3,"Children": [@@ -12899,7 +12899,7 @@"Type": "NodeTable","Properties": {"id": "20260921105011-3srqnh0",- "updated": "20260925094732",+ "updated": "20261003225941","colgroup": "|"},"TableAligns": [@@ -13386,6 +13386,42 @@]}]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "Fold/expand sibling branches under the same parent by clicking a node's fold button"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Alt+Click"+ },+ {+ "Type": "NodeText",+ "Data": " / "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "⌥Click"+ }+ ]+ }+ ]}]},diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.syindex 040b79446d..d4584c1e53 100644--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy@@ -8,7 +8,7 @@"title": "排版元素","title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);","type": "doc",- "updated": "20261002002136"+ "updated": "20261003225941"},"Children": [{@@ -1914,7 +1914,7 @@"HeadingLevel": 2,"Properties": {"id": "20210104091228-wdpx6ev",- "updated": "20260928143000"+ "updated": "20261003225941"},"Children": [{@@ -1937,6 +1937,38 @@}]},+ {+ "ID": "20261003225941-hge6x3e",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20261003225941-hge6x3e",+ "updated": "20261003225941"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "按住 "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Alt"+ },+ {+ "Type": "NodeText",+ "Data": "(macOS 上为 "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "⌥"+ },+ {+ "Type": "NodeText",+ "Data": ")并点击节点的折叠按钮,可统一折叠或展开同一父节点下的兄弟分支。只要还有兄弟分支展开,就统一折叠;全部折叠时,则统一展开。更深层节点的折叠状态保持不变。普通点击只切换当前节点。"+ }+ ]+ },{"ID": "20210104091228-xdtxrto","Type": "NodeMindmap",diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.syindex 7648502d7d..d8912cd5c8 100644--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy@@ -7,7 +7,7 @@"id": "20200813004551-gm0pbn1","title": "快捷键","type": "doc",- "updated": "20261002230606"+ "updated": "20261003225941"},"Children": [{@@ -12878,7 +12878,7 @@"Type": "NodeHeading","Properties": {"id": "20260921105011-hmrchvc",- "updated": "20261001015635"+ "updated": "20261003225941"},"HeadingLevel": 3,"Children": [@@ -12893,7 +12893,7 @@"Type": "NodeTable","Properties": {"id": "20260921105011-fr0uxw6",- "updated": "20260925094732",+ "updated": "20261003225941","colgroup": "|"},"TableAligns": [@@ -13468,6 +13468,42 @@]}]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "点击节点折叠按钮,折叠或展开同一父节点下的兄弟分支"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Alt+点击"+ },+ {+ "Type": "NodeText",+ "Data": " / "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "⌥点击"+ }+ ]+ }+ ]}]},diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.syindex 58f5adddb7..d354ebd52f 100644--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy@@ -8,7 +8,7 @@"title": "排版元素","title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);","type": "doc",- "updated": "20261002002136"+ "updated": "20261003225941"},"Children": [{@@ -1912,7 +1912,7 @@"HeadingLevel": 2,"Properties": {"id": "20211226122008-731sqd6",- "updated": "20260928143000"+ "updated": "20261003225941"},"Children": [{@@ -1935,6 +1935,38 @@}]},+ {+ "ID": "20261003225941-6yr63oi",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20261003225941-6yr63oi",+ "updated": "20261003225941"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "按住 "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Alt"+ },+ {+ "Type": "NodeText",+ "Data": "(macOS 上為 "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "⌥"+ },+ {+ "Type": "NodeText",+ "Data": ")並點擊節點的摺疊按鈕,可統一摺疊或展開同一父節點下的兄弟分支。只要還有兄弟分支展開,就統一摺疊;全部摺疊時,則統一展開。更深層節點的摺疊狀態保持不變。一般點擊只切換目前節點。"+ }+ ]+ },{"ID": "20211226122122-jf2d7wf","Type": "NodeMindmap",diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.syindex e75d241a1e..059a062de8 100644--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy@@ -7,7 +7,7 @@"id": "20211226122549-jktxego","title": "快捷鍵","type": "doc",- "updated": "20261002230606"+ "updated": "20261003225941"},"Children": [{@@ -12884,7 +12884,7 @@"Type": "NodeHeading","Properties": {"id": "20260921105011-z0oyw36",- "updated": "20261001015635"+ "updated": "20261003225941"},"HeadingLevel": 3,"Children": [@@ -12899,7 +12899,7 @@"Type": "NodeTable","Properties": {"id": "20260921105011-f8y6pxv",- "updated": "20260925094732",+ "updated": "20261003225941","colgroup": "|"},"TableAligns": [@@ -13386,6 +13386,42 @@]}]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "點擊節點摺疊按鈕,摺疊或展開同一父節點下的兄弟分支"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Alt+點擊"+ },+ {+ "Type": "NodeText",+ "Data": " / "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "⌥點擊"+ }+ ]+ }+ ]}]},diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.syindex e5600689f0..f48159cf05 100644--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy@@ -9,7 +9,7 @@"id": "20240530101000-xsbxokr","title": "ショートカット","type": "doc",- "updated": "20261002230607"+ "updated": "20261003225941"},"Children": [{@@ -12838,7 +12838,7 @@"Type": "NodeHeading","Properties": {"id": "20260921105011-icqlkb6",- "updated": "20261001015635"+ "updated": "20261003225941"},"HeadingLevel": 3,"Children": [@@ -12853,7 +12853,7 @@"Type": "NodeTable","Properties": {"id": "20260921105011-01k7syf",- "updated": "20260925094732",+ "updated": "20261003225941","colgroup": "|"},"TableAligns": [@@ -13340,6 +13340,42 @@]}]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "ノードの折りたたみボタンで同じ親ノード配下の兄弟ブランチを折りたたみ/展開"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Alt+クリック"+ },+ {+ "Type": "NodeText",+ "Data": " / "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "⌥クリック"+ }+ ]+ }+ ]}]},diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.syindex 96cf5a9e36..546ec2a27c 100644--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy@@ -9,7 +9,7 @@"title": "書式要素","title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;","type": "doc",- "updated": "20261002002136"+ "updated": "20261003225941"},"Children": [{@@ -2044,7 +2044,7 @@"Properties": {"ID": "20240530101000-ch5e4vh","id": "20240530101000-1ev7xub",- "updated": "20260928143000"+ "updated": "20261003225941"},"Children": [{@@ -2067,6 +2067,34 @@}]},+ {+ "ID": "20261003225941-37evcb1",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20261003225941-37evcb1",+ "updated": "20261003225941"+ },+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Alt"+ },+ {+ "Type": "NodeText",+ "Data": "(macOS では "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "⌥"+ },+ {+ "Type": "NodeText",+ "Data": ")を押しながらノードの折りたたみボタンをクリックすると、同じ親ノード配下の兄弟ブランチをまとめて折りたたむ、または展開できます。展開されている兄弟ブランチがあればすべて折りたたみ、すべて折りたたまれていれば展開します。さらに深い階層の折りたたみ状態は保持されます。通常のクリックは現在のノードのみを切り替えます。"+ }+ ]+ },{"ID": "20240530101000-lrwpxpq","Type": "NodeMindmap",diff --git a/app/src/protyle/render/listMindmap/fold.test.ts b/app/src/protyle/render/listMindmap/fold.test.tsindex ac509c32c4..13072dc91e 100644--- a/app/src/protyle/render/listMindmap/fold.test.ts+++ b/app/src/protyle/render/listMindmap/fold.test.ts@@ -3,7 +3,7 @@ import {readFileSync} from "node:fs";import test from "node:test";import {runInNewContext} from "node:vm";import {createSourceFile, isClassDeclaration, isPropertyAssignment, ScriptTarget, transpileModule} from "typescript";-import {getListMindmapFoldStates} from "./fold";+import {getListMindmapFoldStates, getListMindmapSiblingFoldStates} from "./fold";import type {ListMindmapFoldTarget} from "./fold";import type {ListMindmapNode} from "./model";@@ -11,6 +11,29 @@ const node = (id: string, children: ListMindmapNode[] = [], collapsed = false):id, children, collapsed, virtual: false, contentBlocks: [],});+test("sibling folding follows the list toggle rule within one parent and preserves deeper states", () => {+ const deep = node("deep", [node("leaf")], true);+ const a = {...node("a", [deep], true), parentId: "parent"};+ const b = {...node("b", [node("child")]), parentId: "parent"};+ const leaf = {...node("leafSibling"), parentId: "parent"};+ const other = {...node("other", [node("otherChild")]), parentId: "otherParent"};+ const parent = node("parent", [a, b, leaf]);+ const model = {nodes: new Map([parent, a, b, leaf, other, deep].map(item => [item.id, item]))};+ assert.deepEqual([...getListMindmapSiblingFoldStates(model, a.id)], [[a.id, true], [b.id, true]]);+ b.collapsed = true;+ assert.deepEqual([...getListMindmapSiblingFoldStates(model, a.id)], [[a.id, false], [b.id, false]]);+ assert.deepEqual([...getListMindmapSiblingFoldStates(model, a.id, new Map([[a.id, false]]))],+ [[a.id, true], [b.id, true]]);+ assert.equal(deep.collapsed, true);+ assert.equal(other.collapsed, false);+ assert.equal(leaf.collapsed, false);+ assert.equal(getListMindmapSiblingFoldStates(model, "missing").size, 0);+ assert.deepEqual([...getListMindmapSiblingFoldStates(model, parent.id)], [[parent.id, true]]);+ parent.virtual = true;+ assert.deepEqual([...getListMindmapSiblingFoldStates(model, parent.id)], [[parent.id, true]]);+ assert.equal(getListMindmapSiblingFoldStates({nodes: new Map([["leaf", node("leaf")]])}, "leaf").size, 0);+});+test("the selected level expands inclusively and either kind of center counts as level one", () => {for (const virtual of [false, true]) {const root = {...node("root", [node("a", [node("b", [node("leaf")])], true), node("c")]), virtual};@@ -84,19 +107,23 @@ test("batch folding saves a single undo snapshot and reads the source after finiconst controller = source.statements.find(item => isClassDeclaration(item) && item.name?.text === "ListMindmapController");assert.ok(controller && isClassDeclaration(controller));let callback = "";+ let siblingCallback = "";const visit = (item: import("typescript").Node) => {if (isPropertyAssignment(item) && item.name.getText(source) === "onFoldLevel") {callback = item.initializer.getText(source);+ } else if (isPropertyAssignment(item) && item.name.getText(source) === "onFoldSiblings") {+ siblingCallback = item.initializer.getText(source);}item.forEachChild(visit);};visit(controller);assert.ok(callback);+ assert.ok(siblingCallback);const change = controller.members.find(item => item.name?.getText(source) === "change");assert.ok(change);const compiled = transpileModule(`class Controller {${change.getText(source)}- constructor(list) { this.list = list; this.onFoldLevel = ${callback}; }+ constructor(list) { this.list = list; this.onFoldLevel = ${callback}; this.onFoldSiblings = ${siblingCallback}; }}globalThis.Controller = Controller;`, {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;const root = node("root", [node("a", [node("b", [node("leaf")])]), node("c", [node("d")])]);@@ -104,7 +131,10 @@ test("batch folding saves a single undo snapshot and reads the source after finiconst collect = (current: ListMindmapNode) => {nodes.set(current.id, current);current.element = {setAttribute: (_name: string, value: string) => current.collapsed = value === "1"} as unknown as HTMLElement;- current.children.forEach(collect);+ current.children.forEach(child => {+ child.parentId = current.id;+ collect(child);+ });};collect(root);const snapshot = () => JSON.stringify([...nodes].map(([id, current]) => [id, current.collapsed]));@@ -117,6 +147,7 @@ test("batch folding saves a single undo snapshot and reads the source after finigetListMindmapSiblingIDs: () => new Map(),normalizeListMindmapSummaryMetadata: () => {},getListMindmapFoldStates,+ getListMindmapSiblingFoldStates,cleanListMindmapHTML: (html: string) => html,updateTransaction: (_owner: unknown, _list: unknown, before: string) => {if (before !== snapshot()) {@@ -147,7 +178,26 @@ test("batch folding saves a single undo snapshot and reads the source after finiassert.ok(JSON.parse(transactions[1].before).some(([id, collapsed]: [string, boolean]) => id === "b" && collapsed));assert.equal(transactions[1].after, before, "one redo snapshot contains the complete expanded state");target.activeEditor = undefined;+ nodes.get("a").collapsed = true;+ nodes.get("b").collapsed = true;+ const siblingBefore = snapshot();+ assert.equal(await target.onFoldSiblings("a"), true);+ assert.equal(transactions.length, 3);+ assert.equal(transactions[2].before, siblingBefore);+ assert.equal(nodes.get("c").collapsed, true, "a mixed sibling group folds together");+ assert.equal(nodes.get("root").collapsed, false);+ assert.equal(nodes.get("b").collapsed, true, "descendant state is retained");+ assert.equal(await target.onFoldSiblings("a"), true);+ assert.equal(transactions.length, 4);+ assert.equal(nodes.get("a").collapsed, false);+ assert.equal(nodes.get("c").collapsed, false);+ assert.equal(nodes.get("b").collapsed, true);+ target.activeEditor = {finish: async () => false};+ assert.equal(await target.onFoldSiblings("a"), false);+ assert.equal(transactions.length, 4);+ target.activeEditor = undefined;allowed = false;assert.equal(await target.onFoldLevel(1), false);- assert.equal(transactions.length, 2);+ assert.equal(await target.onFoldSiblings("a"), false);+ assert.equal(transactions.length, 4);});diff --git a/app/src/protyle/render/listMindmap/fold.ts b/app/src/protyle/render/listMindmap/fold.tsindex 3d88f3cdd0..98d6cf0b0e 100644--- a/app/src/protyle/render/listMindmap/fold.ts+++ b/app/src/protyle/render/listMindmap/fold.ts@@ -1,7 +1,17 @@-import type {ListMindmapNode} from "./model";+import type {ListMindmapModel, ListMindmapNode} from "./model";export type ListMindmapFoldTarget = number | "expandAll" | "foldAll";+// 同一父节点下仍有展开的分支时统一折叠,否则统一展开,不修改后代的折叠状态。+export const getListMindmapSiblingFoldStates = (model: Pick<ListMindmapModel, "nodes">, id: string,+ folded?: ReadonlyMap<string, boolean>) => {+ const node = model.nodes.get(id);+ const siblings = node?.parentId ? model.nodes.get(node.parentId)?.children || [] : node ? [node] : [];+ const branches = siblings.filter(item => item.children.length);+ const collapsed = branches.some(item => !(folded?.get(item.id) ?? item.collapsed));+ return new Map(branches.map(item => [item.id, collapsed]));+};+// 中心节点为一级,目标级别的节点也展开;折叠下一级分支,保留更深层的折叠状态。export const getListMindmapFoldStates = (root: ListMindmapNode, targetLevel: ListMindmapFoldTarget) => {const states = new Map<string, boolean>();diff --git a/app/src/protyle/render/listMindmap/index.ts b/app/src/protyle/render/listMindmap/index.tsindex 3109432dca..2271480808 100644--- a/app/src/protyle/render/listMindmap/index.ts+++ b/app/src/protyle/render/listMindmap/index.ts@@ -40,7 +40,7 @@ import {setBlockHeight} from "../../gutter/height";import {ListMindmapView} from "./view";import {openListMindmapEditor} from "./editor";import {focusListMindmap} from "./create";-import {getListMindmapFoldStates} from "./fold";+import {getListMindmapFoldStates, getListMindmapSiblingFoldStates} from "./fold";import {isMobile} from "../../../util/functions";import {getListMindmapSiblingIDs, getListMindmapSummaryRange} from "./summary";import {isProtyleListItemFragment} from "../../runtimeCapabilities";@@ -348,6 +348,15 @@ class ListMindmapController {node.element.setAttribute("fold", node.collapsed ? "0" : "1");}}),+ onFoldSiblings: id => this.change(() => {+ const model = readListMindmap(list);+ getListMindmapSiblingFoldStates(model, id).forEach((collapsed, siblingID) => {+ const node = model.nodes.get(siblingID);+ if (node.element && node.collapsed !== collapsed) {+ node.element.setAttribute("fold", collapsed ? "1" : "0");+ }+ });+ }),onUndo: () => this.undo(false),onRedo: () => this.undo(true),onNodeStyle: (id, patch) => this.metadata(metadata => {diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.tsindex 3b07867ba6..01278bdc48 100644--- a/app/src/protyle/render/listMindmap/model.test.ts+++ b/app/src/protyle/render/listMindmap/model.test.ts@@ -166,7 +166,7 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,const check = require("node:assert/strict");const api = new Function("mathRender", "Constants", "highlightRender", sourceCode + "; return {readListMindmap, moveListMindmapNode, addListMindmapNode, " +"deleteListMindmapNode, replaceListMindmapContent, cleanListMindmapHTML, convertListMindmapToList, listMindmapConversionSource, remapListMindmapIDs, writeListMindmapMetadata, retagMindmapBranch, " +- "getListMindmapSiblingIDs, normalizeListMindmapSummaryMetadata, getListMindmapSummaryRange, " ++ "getListMindmapSiblingIDs, normalizeListMindmapSummaryMetadata, getListMindmapSummaryRange, getListMindmapSiblingFoldStates, " +"normalizeLegacyMindmapCodes, replaceLegacyMindmapHTML, spinListMindmapDOM, focusListMindmap, " +"tabsRender, destroyTabsRender, getTabTask, getListMindmapTabItem, convertTabsList, ListMindmapView, registerListMindmapView, resolveVisibleListMindmapBlock, getListMindmapElements, registerListMindmapRoot, restoreListMindmapFocus};")(async (element: Element) => {@@ -2194,6 +2194,94 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,await settle();check.equal(nodeElement(alpha).hidden, false, "level selection expands a previously folded virtual center");levelView.destroy();++ // Alt 点击只切换同一父节点下的分支,普通点击和只读视图沿用各自的折叠行为。+ const siblingHolder = document.createElement("div");+ siblingHolder.innerHTML = lute.Md2BlockDOM("* First\n * A\n * A child\n * A grandchild\n * B\n * B child\n * Leaf\n* Second\n * C\n * C child\n");+ const siblingList = siblingHolder.firstElementChild as HTMLElement;+ const siblingHost = document.createElement("div");+ siblingHost.className = "mindmap-view";+ hostParent.append(siblingHost);+ let siblingModel = api.readListMindmap(siblingList);+ const [a, b, leaf] = siblingModel.root.children[0].children;+ const c = siblingModel.root.children[1].children[0];+ const deep = a.children[0];+ deep.element.setAttribute("fold", "1");+ siblingModel = api.readListMindmap(siblingList);+ const siblingSource = siblingList.outerHTML;+ let siblingFinishAllowed: boolean | Promise<boolean> = true;+ let siblingSaveAllowed = true;+ let siblingSaves = 0;+ const siblingView = new api.ListMindmapView({host: siblingHost, model: siblingModel, readOnly: true,+ finishEdit: () => siblingFinishAllowed,+ onFoldSiblings: async (id: string) => {+ if (!siblingSaveAllowed) {+ return false;+ }+ api.getListMindmapSiblingFoldStates(siblingModel, id).forEach((collapsed: boolean, siblingID: string) => {+ siblingModel.nodes.get(siblingID).element?.setAttribute("fold", collapsed ? "1" : "0");+ });+ siblingSaves++;+ siblingModel = api.readListMindmap(siblingList);+ siblingView.update(siblingModel);+ return true;+ },+ });+ const siblingElement = (id: string) => siblingHost.querySelector<HTMLElement>(`[data-mindmap-id="${id}"]`);+ const clickSiblingFold = async (id: string, altKey = true) => {+ siblingElement(id).querySelector(".mindmap-view__fold").dispatchEvent(new MouseEvent("click", {+ bubbles: true, altKey,+ }));+ await settle();+ };+ await settle();+ await clickSiblingFold(a.id, false);+ check.equal(siblingElement(deep.id).hidden, true, "ordinary clicks only fold the clicked node");+ check.equal(siblingElement(b.children[0].id).hidden, false);+ await clickSiblingFold(b.id);+ check.equal(siblingElement(b.children[0].id).hidden, true, "mixed sibling states fold together");+ check.equal(siblingElement(c.children[0].id).hidden, false, "branches under other parents are untouched");+ check.equal(siblingElement(leaf.id).hidden, false);+ await clickSiblingFold(a.id);+ check.equal(siblingElement(deep.id).hidden, false);+ check.equal(siblingElement(deep.children[0].id).hidden, true, "deeper folding states survive sibling expansion");+ check.equal(siblingElement(b.children[0].id).hidden, false);+ check.equal(siblingList.outerHTML, siblingSource, "read-only sibling folding never writes source attributes");+ check.equal(siblingSaves, 0);+ siblingModel.metadata.viewLocked = true;+ siblingView.update(siblingModel);+ await clickSiblingFold(a.id);+ check.equal(siblingElement(deep.id).hidden, false, "locked views ignore Alt folding");+ siblingModel.metadata.viewLocked = false;+ siblingView.update(siblingModel);+ siblingView.setReadOnly(false);+ siblingSaveAllowed = false;+ await clickSiblingFold(a.id);+ check.equal(siblingElement(deep.id).hidden, false, "failed saves do not change sibling visibility");+ check.equal(siblingList.outerHTML, siblingSource);+ siblingSaveAllowed = true;+ siblingFinishAllowed = false;+ await clickSiblingFold(a.id);+ check.equal(siblingSaves, 0, "failed editor completion blocks sibling folding");+ siblingFinishAllowed = Promise.resolve(true);+ siblingView.selectNode(deep.id);+ await clickSiblingFold(b.id);+ check.equal(siblingSaves, 1);+ check.equal(siblingView.selectedId, a.id, "hidden selections move to the visible ancestor");+ check.equal(siblingElement(deep.id).hidden, true);+ check.equal(siblingElement(b.children[0].id).hidden, true);+ check.equal(siblingModel.nodes.get(c.id).collapsed, false);+ await clickSiblingFold(a.id);+ check.equal(siblingSaves, 2);+ check.equal(siblingElement(deep.id).hidden, false);+ check.equal(siblingElement(deep.children[0].id).hidden, true);+ siblingView.setReadOnly(true);+ await clickSiblingFold(siblingModel.root.id);+ check.equal(siblingElement(a.id).hidden, true, "a virtual center folds locally even without a parent");+ await clickSiblingFold(siblingModel.root.id);+ check.equal(siblingElement(a.id).hidden, false);+ siblingView.destroy();+ siblingHost.remove();list.outerHTML = persistedBeforeFold;list = holder.querySelector<HTMLElement>('[data-type="NodeList"]');model = api.readListMindmap(list);diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex 0cd627e07a..51b25b238c 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -15,7 +15,7 @@ import {getAVRichTextSafeURL} from "../av/richTextValue";import {Constants} from "../../../constants";import {findMindmapDrop} from "./drop";import {destroyTabsRender, tabsRender} from "../tabsRender";-import {getListMindmapFoldStates} from "./fold";+import {getListMindmapFoldStates, getListMindmapSiblingFoldStates} from "./fold";import type {ListMindmapFoldTarget} from "./fold";import {clampMindmapPanOffset} from "./pan";import {getListMindmapSummaryRange, layoutListMindmapSummaries} from "./summary";@@ -49,6 +49,7 @@ export interface ListMindmapViewOptions {onAdd?: (id: string, kind: "child" | "sibling") => void;onDelete?: (id: string) => boolean | void | Promise<boolean | void>;onFold?: (id: string) => void;+ onFoldSiblings?: (id: string) => Promise<boolean>;onFoldLevel?: (level: ListMindmapFoldTarget) => Promise<boolean>;onExpandLevelMenu?: (anchor: HTMLElement, select: (level: ListMindmapFoldTarget) => void) => void;onTaskToggle?: (id: string, cycle?: boolean) => void;@@ -296,7 +297,7 @@ export class ListMindmapView {this.disposers.push(() => target.removeEventListener(event, handler, options));}- private makeButton(key: string, icon: string, action: () => void, className = "") {+ private makeButton(key: string, icon: string, action: (event: MouseEvent) => void, className = "") {const button = createElement("button", "block__icon block__icon--show " + className);button.type = "button";button.setAttribute("aria-label", this.label(key));@@ -306,7 +307,7 @@ export class ListMindmapView {}button.addEventListener("click", (event) => {event.stopPropagation();- this.finishThen(action);+ this.finishThen(() => action(event));});return button;}@@ -602,7 +603,13 @@ export class ListMindmapView {addBridge.hidden = !!this.readOnly;addBridge.setAttribute("aria-hidden", "true");element.append(addBridge);- const fold = this.makeButton("collapse", "iconLeft", () => this.toggleFold(id), "mindmap-view__fold");+ const fold = this.makeButton("collapse", "iconLeft", event => {+ if (event.altKey) {+ void this.toggleSiblingFold(id).catch(error => console.error(error));+ } else {+ this.toggleFold(id);+ }+ }, "mindmap-view__fold");fold.append(createElement("span", "mindmap-view__fold-count"));element.append(fold);const addChild = this.makeButton("listMindmapChild", "iconAdd", () => {@@ -1799,6 +1806,25 @@ export class ListMindmapView {}}+ private async toggleSiblingFold(id: string) {+ if (this.locked) {+ return;+ }+ const states = getListMindmapSiblingFoldStates(this.model, id, this.folded);+ if (!states.size) {+ return;+ }+ const selectedId = this.selectedId;+ this.finishRelationEdit?.(true);+ this.cancelPointer();+ if (!this.readOnly && !await this.options.onFoldSiblings?.(id)) {+ return;+ }+ if (!this.destroyed) {+ this.updateFoldStates(states, selectedId);+ }+ }+private async expandToLevel(level: ListMindmapFoldTarget, selectedId = this.selectedId) {if (this.locked) {return;@@ -1811,7 +1837,11 @@ export class ListMindmapView {if (this.destroyed) {return;}- getListMindmapFoldStates(this.model.root, level).forEach((collapsed, id) => {+ this.updateFoldStates(getListMindmapFoldStates(this.model.root, level), selectedId);+ }++ private updateFoldStates(states: Map<string, boolean>, selectedId: string) {+ states.forEach((collapsed, id) => {if (this.readOnly || this.model.nodes.get(id)?.virtual) {this.folded.set(id, collapsed);} else {