Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Preserve list mind map node dimensions when editing https://github.com/siyuan-note/siyuan/issues/18831

Vanessa3e39e630d4ac
diff --git a/app/src/protyle/render/listMindmap/editor.test.ts b/app/src/protyle/render/listMindmap/editor.test.ts
index 5284efde9e..1d3146d484 100644
--- a/app/src/protyle/render/listMindmap/editor.test.ts
+++ b/app/src/protyle/render/listMindmap/editor.test.ts
@@ -256,15 +256,26 @@ const browserCases = async (sourceCode: string, css: string) => {
const fixture = document.createElement("div");
fixture.className = "protyle-wysiwyg";
document.body.append(fixture);
- for (const text of ["Test text", '<span data-type="strong">11pppppp</span>', "First<br>Second"]) {
+ for (const text of ["Test text", '<span data-type="strong">11pppppp</span>', "First<br>Second",
+ '<span data-type="strong">1水电费ppppp</span>', '<span data-type="strong">1水电费pppppp</span>']) {
fixture.innerHTML = `<div data-node-id="list" data-type="NodeList"><div class="list-mindmap"><div class="list-mindmap__node"><div class="list-mindmap__content"><div class="p"><div>${text}</div></div></div></div></div></div>`;
const node = fixture.querySelector<HTMLElement>(".list-mindmap__node");
const content = fixture.querySelector<HTMLElement>(".list-mindmap__content");
- const before = node.offsetHeight;
- content.style.minWidth = `${content.offsetWidth}px`;
- content.classList.add("list-mindmap__editor", "protyle");
- content.innerHTML = `<div class="protyle-content"><div class="protyle-wysiwyg" spellcheck="false" contenteditable="true"><div class="p" data-node-id="text" data-type="NodeParagraph"><div contenteditable="true" spellcheck="false">${text}</div></div></div></div>`;
- check.equal(node.offsetHeight, before, "entering edit mode preserves node height inside the document");
+ const before = {width: node.offsetWidth, height: node.offsetHeight};
+ const preview = content.innerHTML;
+ for (const scale of [1, 0.65, 1.5]) {
+ fixture.style.transform = `scale(${scale})`;
+ content.style.minWidth = getComputedStyle(content).width;
+ content.classList.add("list-mindmap__editor", "protyle");
+ content.innerHTML = `<div class="protyle-content" data-padding-mode="responsive" data-device="desktop"><div class="protyle-wysiwyg" spellcheck="false" contenteditable="true"><div class="p" data-node-id="text" data-type="NodeParagraph"><div contenteditable="true" spellcheck="false">${text}</div></div></div></div>`;
+ check.deepEqual({width: node.offsetWidth, height: node.offsetHeight}, before,
+ "entering edit mode preserves node dimensions with responsive padding and canvas zoom");
+ content.classList.remove("list-mindmap__editor", "protyle");
+ content.style.minWidth = "";
+ content.innerHTML = preview;
+ check.deepEqual({width: node.offsetWidth, height: node.offsetHeight}, before,
+ "repeated editing does not change preview dimensions");
+ }
}
fixture.remove();
style.remove();
diff --git a/app/src/protyle/render/listMindmap/editor.ts b/app/src/protyle/render/listMindmap/editor.ts
index 24a1b40c0a..a105bbf962 100644
--- a/app/src/protyle/render/listMindmap/editor.ts
+++ b/app/src/protyle/render/listMindmap/editor.ts
@@ -65,8 +65,8 @@ export const openListMindmapEditor = (options: ListMindmapEditorOptions) => {
{key: "[[", hint: hintRef}, {key: "/", hint: slash}, {key: "、", hint: slash}],
};
const originalMinWidth = host.style.minWidth;
- // 挂载前保留未缩放的内容宽度,避免轻量编辑器改变内在尺寸后挤压文字。
- host.style.minWidth = `${host.offsetWidth}px`;
+ // 保留未缩放的亚像素宽度,避免取整后响应式容器挤压文字,导致换行和整棵树重排。
+ host.style.minWidth = getComputedStyle(host).width;
host.replaceChildren();
host.classList.add("list-mindmap__editor");
host.dataset.protyleLiteRender = "safe";
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.ts
index 96d948c32b..d117884d36 100644
--- a/app/src/protyle/render/listMindmap/model.test.ts
+++ b/app/src/protyle/render/listMindmap/model.test.ts
@@ -800,13 +800,21 @@ const browserCases = async (sourceCode: string, css: string) => {
clickLink();
await new Promise(resolve => setTimeout(resolve, 220));
check.deepEqual(opened, ["https://example.com"]);
+ const geometry = () => Array.from(richHost.querySelectorAll(".list-mindmap__node")).map(element => {
+ const rect = element.getBoundingClientRect();
+ return {x: rect.x, y: rect.y, width: rect.width, height: rect.height};
+ });
+ const beforeEditing = geometry();
clickLink();
clickLink(2);
link.dispatchEvent(new MouseEvent("dblclick", {bubbles: true, cancelable: true, detail: 2}));
await new Promise(resolve => setTimeout(resolve, 220));
check.equal(richEdits, 1);
check.equal(opened.length, 1);
+ check.deepEqual(geometry(), beforeEditing, "entering edit mode does not reposition the canvas or other nodes");
richView.setEditing();
+ await settle();
+ check.deepEqual(geometry(), beforeEditing, "leaving edit mode does not reposition the canvas or other nodes");
const point = centerPoint(link);
sendPointer(link, "pointerdown", point.x, point.y);
sendPointer(richHost.querySelector(".list-mindmap__viewport"), "pointermove", point.x + 30, point.y);