An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Preserve mind map position when expanding hidden nodes https://github.com/siyuan-note/siyuan/issues/18831
Vanessa58352db3add6
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.tsindex 5df0cb3ebf..7ec2ec9d16 100644--- a/app/src/protyle/render/listMindmap/model.test.ts+++ b/app/src/protyle/render/listMindmap/model.test.ts@@ -696,8 +696,11 @@ const browserCases = async (sourceCode: string, css: string) => {const persistedBeforeFold = list.outerHTML;pressDelete();check.deepEqual(deletions, [beta]);+ const beforeCollapse = nodeElement(model.root.id).getBoundingClientRect();nodeElement(model.root.id).querySelector<HTMLButtonElement>(".list-mindmap__fold").click();await settle();+ const afterCollapse = nodeElement(model.root.id).getBoundingClientRect();+ check.ok(Math.abs(afterCollapse.y - beforeCollapse.y) < 1, "collapse keeps the root at its screen position");check.equal(nodeElement(alpha).hidden, true);const foldedButton = nodeElement(model.root.id).querySelector<HTMLButtonElement>(".list-mindmap__fold");check.equal(foldedButton.querySelector("span").textContent, String(model.nodes.size - 1));@@ -705,6 +708,9 @@ const browserCases = async (sourceCode: string, css: string) => {foldedButton.click();await settle();check.equal(nodeElement(alpha).hidden, false);+ const afterExpand = nodeElement(model.root.id).getBoundingClientRect();+ check.ok(Math.abs(afterExpand.y - afterCollapse.y) < 1, "expansion keeps the root stable after size observers settle");+ check.ok(Math.abs(afterExpand.x - afterCollapse.x) < 1, "expansion preserves horizontal position");check.equal(list.outerHTML, persistedBeforeFold);readonly.destroy();diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex 70710ee4e6..2b7e4b0f2b 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -96,7 +96,7 @@ export class ListMindmapView {private scale = 1;private offsetX = 0;private offsetY = 0;- private foldAnchor?: string;+ private foldAnchor?: {id: string, collapsed: boolean};private frame = 0;private initialFit = true;private destroyed = false;@@ -469,6 +469,8 @@ export class ListMindmapView {if (!this.viewport.clientWidth || !this.viewport.clientHeight) {return;}+ // 同一帧内先恢复测量,布局完成后再隐藏折叠后代,避免展开时读取到零尺寸。+ this.nodeElements.forEach(element => element.hidden = false);const makeLayoutNode = (id: string): ListMindmapLayoutNode => {const node = this.model.nodes.get(id);const element = this.nodeElements.get(id);@@ -480,7 +482,7 @@ export class ListMindmapView {children: node.children.map(child => makeLayoutNode(child.id)),};};- const anchorId = this.editingId || this.foldAnchor;+ const anchorId = this.editingId || this.foldAnchor?.id;const previous = anchorId ? this.positions.get(anchorId) : undefined;const result = layoutListMindmap(makeLayoutNode(this.model.root.id));this.positions = result.nodes;@@ -529,7 +531,10 @@ export class ListMindmapView {this.offsetX += (previous.x - current.x) * this.scale;this.offsetY += (previous.y - current.y) * this.scale;}- this.foldAnchor = undefined;+ if (this.foldAnchor && (this.folded.get(this.foldAnchor.id) ??+ this.model.nodes.get(this.foldAnchor.id)?.collapsed) === this.foldAnchor.collapsed) {+ this.foldAnchor = undefined;+ }if (this.initialFit) {this.initialFit = false;this.fit();@@ -809,7 +814,7 @@ export class ListMindmapView {if (!node?.children.length) {return;}- this.foldAnchor = id;+ this.foldAnchor = {id, collapsed: !(this.folded.get(id) ?? node.collapsed)};if (this.options.readOnly || node.virtual) {this.folded.set(id, !(this.folded.get(id) ?? node.collapsed));this.update(this.model);