Skip to content

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

:sparkles: Improve mind map editing, root titles and keyboard shortcuts https://github.com/siyuan-note/siyuan/issues/19622

Vanessa30693391c346
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.sy
index af41c27970..504f62964f 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": "20260913160005"
+ "updated": "20260918210804"
},
"Children": [
{
@@ -17922,6 +17922,38 @@
]
}
]
+ },
+ {
+ "ID": "20260918210804-ba0cedp",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260918210804-ba0cedp",
+ "updated": "20260918210804"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "In a list mind map, when a node is selected but not being edited, press "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Tab"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " to create a child node or "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Enter"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " to create and edit a sibling node. Virtual roots cannot have siblings; editing retains the editor's key behavior"
+ }
+ ]
}
]
}
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.sy
index f812e26621..12dd2b1592 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": "20260913160005"
+ "updated": "20260918210804"
},
"Children": [
{
@@ -17862,6 +17862,38 @@
"Properties": {
"id": "20220902201142-hyb8kfm"
}
+ },
+ {
+ "ID": "20260918210804-v5fqgbn",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260918210804-v5fqgbn",
+ "updated": "20260918210804"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "列表脑图中,节点选中且未编辑时,按 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Tab"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 创建子节点,按 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Enter"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 创建同级节点并编辑;虚拟根节点不创建同级节点,编辑状态保留编辑器的按键行为"
+ }
+ ]
}
]
}
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.sy
index 7c11c1ffea..1d0841ffea 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": "20260913160005"
+ "updated": "20260918210804"
},
"Children": [
{
@@ -17925,6 +17925,38 @@
"Properties": {
"id": "20220902195830-i3ncplk"
}
+ },
+ {
+ "ID": "20260918210804-t0jvlna",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260918210804-t0jvlna",
+ "updated": "20260918210804"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "列表腦圖中,節點選中且未編輯時,按 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Tab"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 建立子節點,按 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Enter"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 建立同級節點並編輯;虛擬根節點不建立同級節點,編輯狀態保留編輯器的按鍵行為"
+ }
+ ]
}
]
}
diff --git a/app/src/assets/scss/protyle/_list-mindmap.scss b/app/src/assets/scss/protyle/_list-mindmap.scss
index f9d93a9b64..d1659419bc 100644
--- a/app/src/assets/scss/protyle/_list-mindmap.scss
+++ b/app/src/assets/scss/protyle/_list-mindmap.scss
@@ -290,6 +290,51 @@
}
}
+ &__editor .protyle-content[data-padding-mode] {
+ container-type: normal;
+ }
+
+ &__text {
+ min-height: 1.5em;
+ white-space: break-spaces;
+ word-break: break-word;
+
+ &--trailing-newline::after {
+ content: "\200b";
+ }
+ }
+
+ &__root-title-host {
+ position: relative;
+ }
+
+ &__root-title-measure {
+ display: block;
+ visibility: hidden;
+ white-space: pre-wrap;
+ overflow-wrap: anywhere;
+ }
+
+ &__root-title {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ min-width: 0;
+ padding: 0;
+ margin: 0;
+ border: 0;
+ outline: none;
+ resize: none;
+ overflow: hidden;
+ box-sizing: border-box;
+ font: inherit;
+ color: inherit;
+ background: transparent;
+ white-space: pre-wrap;
+ overflow-wrap: anywhere;
+ }
+
&__fold {
position: absolute;
z-index: 1;
diff --git a/app/src/protyle/render/listMindmap/editor.test.ts b/app/src/protyle/render/listMindmap/editor.test.ts
index 1d3146d484..bfd4bf7707 100644
--- a/app/src/protyle/render/listMindmap/editor.test.ts
+++ b/app/src/protyle/render/listMindmap/editor.test.ts
@@ -256,9 +256,9 @@ 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", "First\nSecond",
'<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>`;
+ 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 class="list-mindmap__text">${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 = {width: node.offsetWidth, height: node.offsetHeight};
@@ -270,6 +270,14 @@ const browserCases = async (sourceCode: string, css: string) => {
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.style.minWidth = "";
+ const editable = content.querySelector<HTMLElement>('[data-type="NodeParagraph"] > div');
+ editable.textContent = "A longer sentence that expands the node while editing";
+ const expandedWidth = node.offsetWidth;
+ check.ok(expandedWidth > before.width, "typing expands the editor before blur");
+ check.ok(expandedWidth <= 300, "editing respects the existing maximum width");
+ editable.textContent = "A";
+ check.ok(node.offsetWidth < expandedWidth, "deleting text shrinks the editor before blur");
content.classList.remove("list-mindmap__editor", "protyle");
content.style.minWidth = "";
content.innerHTML = preview;
diff --git a/app/src/protyle/render/listMindmap/editor.ts b/app/src/protyle/render/listMindmap/editor.ts
index a105bbf962..f55d229415 100644
--- a/app/src/protyle/render/listMindmap/editor.ts
+++ b/app/src/protyle/render/listMindmap/editor.ts
@@ -93,6 +93,7 @@ export const openListMindmapEditor = (options: ListMindmapEditorOptions) => {
return;
}
changed = true;
+ host.style.minWidth = originalMinWidth;
options.onResize();
if (saving) {
return;
diff --git a/app/src/protyle/render/listMindmap/index.ts b/app/src/protyle/render/listMindmap/index.ts
index d6757f0f8a..d4ff39c280 100644
--- a/app/src/protyle/render/listMindmap/index.ts
+++ b/app/src/protyle/render/listMindmap/index.ts
@@ -171,6 +171,9 @@ class ListMindmapController {
}
},
onEdit: (id, contentHost) => this.edit(id, contentHost),
+ onRootTitleChange: title => this.metadata(metadata => {
+ metadata.rootTitle = title;
+ }),
onMove: (id, target, placement) => this.change(() => moveListMindmapNode(list, id, target, placement)),
onAdd: async (id, kind) => {
const target = this.model.nodes.get(id);
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.ts
index 71d89e9c02..87b470ec3e 100644
--- a/app/src/protyle/render/listMindmap/model.test.ts
+++ b/app/src/protyle/render/listMindmap/model.test.ts
@@ -85,7 +85,7 @@ test("layout rejects cyclic or invalid trees and supports deep nesting without r
const browserCases = async (sourceCode: string, css: string) => {
const check = require("node:assert/strict");
const api = new Function("mathRender", "Constants", sourceCode + "; return {readListMindmap, moveListMindmapNode, addListMindmapNode, " +
- "deleteListMindmapNode, replaceListMindmapContent, cleanListMindmapHTML, remapListMindmapIDs, ListMindmapView};")(
+ "deleteListMindmapNode, replaceListMindmapContent, cleanListMindmapHTML, remapListMindmapIDs, writeListMindmapMetadata, ListMindmapView};")(
async (element: Element) => {
const formulas = element.querySelectorAll('[data-subtype="math"]:not([data-render="true"])');
await Promise.resolve();
@@ -490,6 +490,23 @@ const browserCases = async (sourceCode: string, css: string) => {
sendPointer(nodeElement(id), "pointerdown", point.x, point.y);
sendPointer(viewport, "pointerup", point.x, point.y);
};
+ select(beta);
+ const beforeShortcuts = additions.length;
+ const originalEditable = host.parentElement.contentEditable;
+ host.parentElement.contentEditable = "true";
+ for (const key of ["Tab", "Enter"]) {
+ const event = new KeyboardEvent("keydown", {key, bubbles: true, cancelable: true});
+ host.dispatchEvent(event);
+ check.equal(event.defaultPrevented, true, "nested mindmap handles keys instead of moving toolbar focus");
+ }
+ check.deepEqual(additions.slice(beforeShortcuts), [[beta, "child"], [beta, "sibling"]]);
+ view.setEditing(beta);
+ host.dispatchEvent(new KeyboardEvent("keydown", {key: "Tab", bubbles: true}));
+ host.dispatchEvent(new KeyboardEvent("keydown", {key: "Enter", bubbles: true}));
+ check.equal(additions.length, beforeShortcuts + 2, "editing does not create nodes via selection shortcuts");
+ view.setEditing();
+ additions.length = beforeShortcuts;
+ host.parentElement.contentEditable = originalEditable;
const blank = () => {
const rect = viewport.getBoundingClientRect();
sendPointer(viewport, "pointerdown", rect.left + 5, rect.top + 5);
@@ -717,6 +734,40 @@ const browserCases = async (sourceCode: string, css: string) => {
check.equal(list.outerHTML, persistedBeforeFold);
readonly.destroy();
+ const titleView = new api.ListMindmapView({...options, onRootTitleChange: (title: string) => {
+ model.metadata.rootTitle = title;
+ api.writeListMindmapMetadata(list, model.metadata);
+ titleView.update(model);
+ }});
+ await settle();
+ const renameRoot = async (title: string, key: string) => {
+ const node = nodeElement(model.root.id);
+ const before = {width: node.offsetWidth, height: node.offsetHeight};
+ titleView.getContentHost(model.root.id).dispatchEvent(new MouseEvent("dblclick", {bubbles: true}));
+ const input = host.querySelector<HTMLTextAreaElement>(".list-mindmap__root-title");
+ check.ok(input, "virtual root supports inline title editing");
+ check.deepEqual({width: node.offsetWidth, height: node.offsetHeight}, before,
+ "entering root title editing preserves dimensions");
+ input.value = "A long root title that grows while typing";
+ input.dispatchEvent(new Event("input", {bubbles: true}));
+ await settle();
+ const expanded = node.offsetWidth;
+ input.value = "A";
+ input.dispatchEvent(new Event("input", {bubbles: true}));
+ await settle();
+ check.ok(node.offsetWidth < expanded, "root title resizes before leaving the editor");
+ input.value = title;
+ input.dispatchEvent(new KeyboardEvent("keydown", {key, bubbles: true}));
+ };
+ await renameRoot("Custom root", "Enter");
+ check.equal(api.readListMindmap(list).metadata.rootTitle, "Custom root");
+ check.equal(titleView.getContentHost(model.root.id).textContent, "Custom root");
+ await renameRoot("Canceled title", "Escape");
+ check.equal(titleView.getContentHost(model.root.id).textContent, "Custom root");
+ await renameRoot("", "Enter");
+ check.equal(titleView.getContentHost(model.root.id).textContent, "listMindmapRoot");
+ titleView.destroy();
+
const singleList = reset("* Single\n");
const single = new api.ListMindmapView({...options, model: api.readListMindmap(singleList)});
const emptyModel = api.readListMindmap(singleList);
@@ -728,6 +779,23 @@ const browserCases = async (sourceCode: string, css: string) => {
check.equal(emptyContent.classList.contains("list-mindmap__content--empty"), true);
check.equal(emptyContent.dataset.placeholder, "listMindmapPlaceholder");
check.equal(emptyContent.textContent, "", "placeholder is not node content");
+ emptyBlock.innerHTML = '<div spellcheck="false">First\n\n\nLast</div>';
+ single.update(emptyModel);
+ await settle();
+ const textPreview = emptyContent.querySelector<HTMLElement>(".list-mindmap__text");
+ const lineHeight = parseFloat(getComputedStyle(textPreview).lineHeight);
+ check.ok(textPreview.offsetHeight >= lineHeight * 4, "consecutive soft breaks retain blank lines");
+ emptyBlock.innerHTML = '<div spellcheck="false">\n\n</div>';
+ single.update(emptyModel);
+ await settle();
+ check.equal(emptyContent.classList.contains("list-mindmap__content--empty"), false);
+ check.ok(emptyContent.offsetHeight >= lineHeight * 3, "blank-only and trailing lines remain visible");
+ emptyBlock.innerHTML = '<div spellcheck="false"></div>';
+ emptyModel.root.contentBlocks = [emptyBlock, emptyBlock.cloneNode(true), emptyBlock.cloneNode(true)];
+ single.update(emptyModel);
+ await settle();
+ check.ok(emptyContent.offsetHeight >= lineHeight * 3, "empty paragraphs retain individual line height");
+ emptyModel.root.contentBlocks = [emptyBlock];
emptyBlock.innerHTML = '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">';
single.update(emptyModel);
check.equal(emptyContent.classList.contains("list-mindmap__content--empty"), false);
diff --git a/app/src/protyle/render/listMindmap/model.ts b/app/src/protyle/render/listMindmap/model.ts
index 9897b144c3..749c9c6227 100644
--- a/app/src/protyle/render/listMindmap/model.ts
+++ b/app/src/protyle/render/listMindmap/model.ts
@@ -29,6 +29,7 @@ export interface ListMindmapRelation {
export interface ListMindmapMetadata {
version: 1;
+ rootTitle?: string;
nodes: Record<string, ListMindmapNodeStyle>;
relations: ListMindmapRelation[];
}
@@ -89,6 +90,9 @@ export const parseListMindmapMetadata = (value: string | null): ListMindmapMetad
throw invalidMetadata();
}
const stringKeys = ["textColor", "backgroundColor", "borderColor", "lineColor"];
+ if (data.rootTitle !== undefined && typeof data.rootTitle !== "string") {
+ throw invalidMetadata();
+ }
const numberKeys = ["fontSize", "borderWidth", "borderRadius", "lineWidth"];
const booleanKeys = ["bold", "italic", "lineDash"];
for (const [id, style] of Object.entries(data.nodes)) {
diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.ts
index 117fc6b55f..68f8e20114 100644
--- a/app/src/protyle/render/listMindmap/view.ts
+++ b/app/src/protyle/render/listMindmap/view.ts
@@ -28,6 +28,7 @@ export interface ListMindmapViewOptions {
onManageLineColors?: () => void;
onFullscreen?: (enter: boolean, button: HTMLButtonElement) => void;
onEdit?: (id: string, contentHost: HTMLElement) => void;
+ onRootTitleChange?: (title: string) => void;
finishEdit?: () => boolean | void | Promise<boolean | void>;
onMove?: (id: string, targetId: string, placement: "before" | "child" | "after") => void;
onAdd?: (id: string, kind: "child" | "sibling") => void;
@@ -373,7 +374,7 @@ export class ListMindmapView {
addBridge.hidden = !!this.options.readOnly;
addBridge.setAttribute("aria-hidden", "true");
element.append(addBridge);
- const fold = this.makeButton("collapse", "iconDown", () => this.toggleFold(id), "list-mindmap__fold");
+ const fold = this.makeButton("collapse", "iconLeft", () => this.toggleFold(id), "list-mindmap__fold");
fold.append(createElement("span", "list-mindmap__fold-count"));
element.append(fold);
const addChild = this.makeButton("listMindmapChild", "iconAdd", () => {
@@ -404,12 +405,16 @@ export class ListMindmapView {
const content = this.getContentHost(id);
content.replaceChildren();
if (node.virtual) {
- content.textContent = this.label("listMindmapRoot");
+ content.textContent = this.model.metadata.rootTitle || this.label("listMindmapRoot");
} else {
node.contentBlocks.forEach((block) => {
const clone = block.cloneNode(true) as HTMLElement;
clone.querySelectorAll(".protyle-attr, .protyle-action, .protyle-icons, .list-mindmap").forEach(item => item.remove());
[clone, ...Array.from(clone.querySelectorAll<HTMLElement>("*"))].forEach((item) => {
+ if (item.hasAttribute("spellcheck")) {
+ item.classList.add("list-mindmap__text");
+ item.classList.toggle("list-mindmap__text--trailing-newline", item.textContent.endsWith("\n"));
+ }
item.removeAttribute("contenteditable");
item.removeAttribute("data-node-id");
item.removeAttribute("spellcheck");
@@ -421,7 +426,9 @@ export class ListMindmapView {
content.append(clone);
});
}
- const empty = !content.textContent.replace(/[\u200b\ufeff]/g, "").trim() &&
+ const hasBlankLines = node.contentBlocks.length > 1 || content.textContent.includes("\n") ||
+ content.querySelectorAll("br").length > 1;
+ const empty = !hasBlankLines && !content.textContent.replace(/[\u200b\ufeff]/g, "").trim() &&
!content.querySelector("img, svg, video, audio, iframe, canvas, hr, [data-content]");
content.classList.toggle("list-mindmap__content--empty", empty);
content.dataset.placeholder = this.label("listMindmapPlaceholder");
@@ -1123,18 +1130,66 @@ export class ListMindmapView {
}
return;
}
- if (!id || this.model.nodes.get(id)?.virtual) {
+ if (!id) {
return;
}
event.preventDefault();
event.stopPropagation();
this.cancelPointer();
this.finishThen(() => {
+ if (this.model.nodes.get(id)?.virtual) {
+ this.editRootTitle(id);
+ return;
+ }
this.setEditing(id);
this.options.onEdit?.(id, this.getContentHost(id));
});
};
+ private editRootTitle(id: string) {
+ this.finishRelationEdit?.(true);
+ const content = this.getContentHost(id);
+ const input = createElement("textarea", "list-mindmap__root-title");
+ const measure = createElement("span", "list-mindmap__root-title-measure");
+ input.rows = 1;
+ input.value = this.model.metadata.rootTitle || this.label("listMindmapRoot");
+ measure.textContent = input.value;
+ input.setAttribute("aria-label", this.label("text"));
+ content.classList.add("list-mindmap__root-title-host");
+ this.setEditing(id);
+ content.replaceChildren(measure, input);
+ input.addEventListener("input", () => {
+ measure.textContent = input.value || "\u200b";
+ this.refreshLayout();
+ });
+ let finished = false;
+ const finish = (save: boolean) => {
+ if (finished) {
+ return;
+ }
+ finished = true;
+ this.finishRelationEdit = undefined;
+ const title = input.value.trim();
+ content.classList.remove("list-mindmap__root-title-host");
+ this.setEditing(undefined);
+ if (save && title !== (this.model.metadata.rootTitle || "")) {
+ this.options.onRootTitleChange?.(title);
+ }
+ this.update(this.model);
+ };
+ this.finishRelationEdit = finish;
+ input.addEventListener("blur", () => finish(true));
+ input.addEventListener("keydown", event => {
+ event.stopPropagation();
+ if (!event.isComposing && (event.key === "Enter" || event.key === "Escape")) {
+ event.preventDefault();
+ finish(event.key === "Enter");
+ }
+ });
+ input.focus();
+ input.select();
+ }
+
private editRelationLabel(event: MouseEvent) {
const relation = this.model.metadata.relations.find(item => item.id === this.selectedRelation);
const element = this.relationElements.get(this.selectedRelation);
@@ -1232,7 +1287,22 @@ export class ListMindmapView {
if (event.isComposing || target.closest("input, textarea, select, .list-mindmap__node--editing")) {
return;
}
- if ((event.key === "Delete" || event.key === "Backspace") &&
+ if ((event.key === "Tab" || event.key === "Enter") && !this.options.readOnly &&
+ !this.editingId && !this.relationFrom && this.selectedId && !event.repeat &&
+ !event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey &&
+ !target.isContentEditable && !target.closest("button, a")) {
+ const id = this.selectedId;
+ const node = this.model.nodes.get(id);
+ if (!node || (event.key === "Enter" && node.virtual)) {
+ return;
+ }
+ const kind = event.key === "Tab" ? "child" : "sibling";
+ this.finishThen(() => {
+ if (this.selectedId === id) {
+ this.options.onAdd?.(id, kind);
+ }
+ });
+ } else if ((event.key === "Delete" || event.key === "Backspace") &&
!event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
const selectedId = this.selectedId;
const selectedRelation = this.selectedRelation;
diff --git a/docs/LIST-MINDMAP.md b/docs/LIST-MINDMAP.md
index 7e3a24d8b8..1a3a16f633 100644
--- a/docs/LIST-MINDMAP.md
+++ b/docs/LIST-MINDMAP.md
@@ -6,6 +6,9 @@
- 按住节点拖动,调整同级顺序或父子层级;目标节点上部、中心、下部分别表示放在前面、作为子节点、放在后面,松手后自动布局
- 双击节点正文才创建轻量 Protyle,直接在原节点内编辑;文字选择和输入由编辑器接管
+- 节点选中且未编辑时,Tab 创建子节点,Enter 创建同级节点,并进入新节点编辑;虚拟根节点不创建同级节点,编辑状态保留 Protyle 的按键行为
+- 编辑节点时随内容增长或缩短实时调整宽度,保留 300px 的最大宽度;仅进入编辑时保持原有尺寸
+- 双击虚拟根节点的标题可原地修改,Enter 或移开焦点保存,Esc 取消;留空恢复“当前列表”,标题随列表属性保存并支持撤销
- 编辑能力复用数据库文本字段的轻量 Protyle,同时保留既有图片;不支持编辑的复杂正文保留原数据,可切回列表编辑
- 点击编辑器外部或按 Esc 结束编辑,保存前等待 Protyle 完成待处理输入;候选菜单和格式菜单优先处理 Esc
- 鼠标移入节点时,右侧显示添加子节点的加号;点击后自动展开父节点,并直接进入新节点编辑
@@ -19,7 +22,7 @@
## 数据与兼容性
-正文仍存放在原列表和原列表项中,搜索、块引用和反链继续使用原块 ID。单个顶层列表项直接作为根节点;多个顶层项使用只读的虚拟中心节点,它不新增实际块。
+正文仍存放在原列表和原列表项中,搜索、块引用和反链继续使用原块 ID。单个顶层列表项直接作为根节点;多个顶层项使用可自定义标题的虚拟中心节点,它不新增实际块,标题存放在脑图属性的可选 `rootTitle` 字段中。
列表块使用 `custom-list-mindmap="1"` 启用脑图视图。`custom-list-mindmap-data` 保存版本为 `1` 的节点样式和关系线配置。关闭脑图视图保留该配置;折叠使用列表项的已有 `fold` 属性。未知版本或损坏的配置不会被自动覆盖,原列表仍可查看。