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: Align mind map editing with list interactions https://github.com/siyuan-note/siyuan/issues/20893
Daniel217ad1c6cb82
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 cee3e90712..96bbefb222 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": "20261024163013"+ "updated": "20261026090134"},"Children": [{@@ -13180,7 +13180,7 @@"Type": "NodeHeading","Properties": {"id": "20260921105011-4zeuyl4",- "updated": "20261024124323"+ "updated": "20261026090134"},"HeadingLevel": 3,"Children": [@@ -13241,7 +13241,7 @@"Type": "NodeTable","Properties": {"id": "20260921105011-3srqnh0",- "updated": "20261020162345",+ "updated": "20261026090134","colgroup": "|"},"TableAligns": [@@ -13344,7 +13344,7 @@"Children": [{"Type": "NodeText",- "Data": "Create a child node"+ "Data": "Create a child node when selected"}]},@@ -13371,7 +13371,34 @@"Children": [{"Type": "NodeText",- "Data": "Create a sibling node"+ "Data": "Create a sibling node when selected"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Enter"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "Split the first paragraph at the caret into a sibling node"}]},@@ -13388,6 +13415,141 @@}]},+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "Indent the edited branch under its previous sibling"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Tab"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "Outdent the edited branch"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Shift+Tab"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "Insert a soft line break while editing"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Shift+Enter"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "At the start of the first paragraph, merge the body into the previous sibling"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Backspace"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "At the end of the last paragraph, merge the next sibling body into this node"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Delete"+ }+ ]+ }+ ]+ },{"Type": "NodeTableRow","Data": "tr",@@ -13911,6 +14073,20 @@}]},+ {+ "ID": "20261026090134-16w12i9",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20261026090134-16w12i9",+ "updated": "20261026090134"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "While editing a node, Enter in its first paragraph creates a sibling and continues editing there; text after the caret and subsequent content blocks move to the new node. At the start of a nonempty first paragraph, it inserts an empty node before the current node. Tab and Shift+Tab move the whole branch while preserving its child nodes. Merge adjacent nodes with Backspace at the start or Delete at the end to keep multiple paragraphs in one node. Other content blocks retain their normal Enter behavior, and code blocks, tables, input methods and suggestion menus retain their editing controls. Existing customized editor shortcuts take precedence."+ }+ ]+ },{"ID": "20261020162345-sclp2zh","Type": "NodeParagraph",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 464e9ade9f..da8dacfe55 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": "20261024163013"+ "updated": "20261026090134"},"Children": [{@@ -13162,7 +13162,7 @@"Type": "NodeHeading","Properties": {"id": "20260921105011-hmrchvc",- "updated": "20261024124323"+ "updated": "20261026090134"},"HeadingLevel": 3,"Children": [@@ -13223,7 +13223,7 @@"Type": "NodeTable","Properties": {"id": "20260921105011-fr0uxw6",- "updated": "20261020162345",+ "updated": "20261026090134","colgroup": "|"},"TableAligns": [@@ -13394,6 +13394,168 @@}]},+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "在首段光标处拆分并新建同级节点"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Enter"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "将正在编辑的分支缩进到前一个同级节点下"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Tab"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "将正在编辑的分支反缩进"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Shift+Tab"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "编辑时插入段内换行"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Shift+Enter"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "在首段开头将正文合并到前一个同级节点"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Backspace"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "在末段结尾将后一个同级节点的正文合并到当前节点"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Delete"+ }+ ]+ }+ ]+ },{"Type": "NodeTableRow","Data": "tr",@@ -13981,6 +14143,20 @@}]},+ {+ "ID": "20261026090134-rkj6fmc",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20261026090134-rkj6fmc",+ "updated": "20261026090134"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "编辑节点时,在首段按 Enter 会新建同级节点并继续编辑,光标后的文字和后续内容块移入新节点;在非空首段开头按 Enter 会在当前节点之前插入空节点。Tab 和 Shift+Tab 调整整个分支的缩进,保留子节点。可在节点开头按 Backspace,或在节点结尾按 Delete 合并相邻节点的正文,在一个节点中保留多个段落。其他内容块的 Enter 沿用普通编辑行为,代码块、表格、输入法和候选菜单保留各自的编辑操作;已有的自定义编辑器快捷键优先。"+ }+ ]+ },{"ID": "20261020162345-u2w43bx","Type": "NodeParagraph",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 1ecf617722..536f037c5b 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": "20261024164629"+ "updated": "20261026090134"},"Children": [{@@ -13222,7 +13222,7 @@"Type": "NodeHeading","Properties": {"id": "20260921105011-z0oyw36",- "updated": "20261024124323"+ "updated": "20261026090134"},"HeadingLevel": 3,"Children": [@@ -13283,7 +13283,7 @@"Type": "NodeTable","Properties": {"id": "20260921105011-f8y6pxv",- "updated": "20261020162345",+ "updated": "20261026090134","colgroup": "|"},"TableAligns": [@@ -13386,7 +13386,7 @@"Children": [{"Type": "NodeText",- "Data": "建立子節點"+ "Data": "選取節點時建立子節點"}]},@@ -13413,7 +13413,34 @@"Children": [{"Type": "NodeText",- "Data": "建立同級節點"+ "Data": "選取節點時建立同層級節點"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Enter"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "在首段游標處拆分並建立同層級節點"}]},@@ -13430,6 +13457,141 @@}]},+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "將正在編輯的分支縮排至前一個同層級節點下"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Tab"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "將正在編輯的分支反向縮排"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Shift+Tab"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "編輯時插入段內換行"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Shift+Enter"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "在首段開頭將內文合併至前一個同層級節點"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Backspace"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "在末段結尾將後一個同層級節點的內文合併至目前節點"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Delete"+ }+ ]+ }+ ]+ },{"Type": "NodeTableRow","Data": "tr",@@ -13953,6 +14115,20 @@}]},+ {+ "ID": "20261026090134-8bngrps",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20261026090134-8bngrps",+ "updated": "20261026090134"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "編輯節點時,在首段按 Enter 會建立同層級節點並繼續編輯,游標後的文字和後續內容區塊移入新節點;在非空首段開頭按 Enter 會在目前節點之前插入空節點。Tab 和 Shift+Tab 調整整個分支的縮排,保留子節點。可在節點開頭按 Backspace,或在節點結尾按 Delete 合併相鄰節點的內文,在一個節點中保留多個段落。其他內容區塊的 Enter 沿用一般編輯行為,程式碼區塊、表格、輸入法和候選選單保留各自的編輯操作;既有的自訂編輯器快捷鍵優先。"+ }+ ]+ },{"ID": "20261020162345-8p35hlz","Type": "NodeParagraph",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 6853a65aa5..e1329d29b8 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": "20261024164629"+ "updated": "20261026090134"},"Children": [{@@ -13176,7 +13176,7 @@"Type": "NodeHeading","Properties": {"id": "20260921105011-icqlkb6",- "updated": "20261024124323"+ "updated": "20261026090134"},"HeadingLevel": 3,"Children": [@@ -13219,7 +13219,7 @@"Type": "NodeTable","Properties": {"id": "20260921105011-01k7syf",- "updated": "20261020162345",+ "updated": "20261026090134","colgroup": "|"},"TableAligns": [@@ -13322,7 +13322,7 @@"Children": [{"Type": "NodeText",- "Data": "子ノードを作成"+ "Data": "選択中に子ノードを作成"}]},@@ -13349,7 +13349,34 @@"Children": [{"Type": "NodeText",- "Data": "同階層のノードを作成"+ "Data": "選択中に同階層のノードを作成"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Enter"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "最初の段落をカーソル位置で分割して同階層のノードを作成"}]},@@ -13366,6 +13393,141 @@}]},+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "編集中の分岐を直前の同階層ノードの子にする"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Tab"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "編集中の分岐を1階層上げる"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Shift+Tab"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "編集中に段落内で改行"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Shift+Enter"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "最初の段落の先頭で本文を直前の同階層ノードに結合"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Backspace"+ }+ ]+ }+ ]+ },+ {+ "Type": "NodeTableRow",+ "Data": "tr",+ "Children": [+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeText",+ "Data": "最後の段落の末尾で次の同階層ノードの本文を結合"+ }+ ]+ },+ {+ "Type": "NodeTableCell",+ "Data": "td",+ "Children": [+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Delete"+ }+ ]+ }+ ]+ },{"Type": "NodeTableRow","Data": "tr",@@ -13889,6 +14051,20 @@}]},+ {+ "ID": "20261026090134-ly6n91j",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20261026090134-ly6n91j",+ "updated": "20261026090134"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "ノードの最初の段落を編集中に Enter を押すと、同階層のノードを作成して編集を続けます。カーソル以降の文字と後続のコンテンツブロックは新しいノードに移ります。空でない最初の段落の先頭では、現在のノードの前に空のノードを挿入します。Tab と Shift+Tab は子ノードを保持したまま分岐全体の階層を変更します。先頭で Backspace、末尾で Delete を押すと隣接ノードの本文を結合でき、1つのノードに複数の段落を保持できます。他のコンテンツブロックでは通常の Enter の動作を使います。コードブロック、表、入力メソッド、候補メニューの編集操作は維持され、既存のカスタム編集ショートカットが優先されます。"+ }+ ]+ },{"ID": "20261020162345-6y84piz","Type": "NodeParagraph",diff --git a/app/src/protyle/render/listMindmap/editor.test.ts b/app/src/protyle/render/listMindmap/editor.test.tsindex 188e45483c..0409ad07d8 100644--- a/app/src/protyle/render/listMindmap/editor.test.ts+++ b/app/src/protyle/render/listMindmap/editor.test.ts@@ -74,6 +74,7 @@ const browserCases = async (sourceCode: string, css: string, cleanupSource: strifinished: 0,saves: [] as string[],additions: [] as string[],+ listInputs: [] as import("./listInput").ListMindmapListInput[],messages: [] as string[],accept: true,flush: async (): Promise<void> => undefined,@@ -190,6 +191,7 @@ const browserCases = async (sourceCode: string, css: string, cleanupSource: stricanEdit: () => element.isConnected,onResize: noop,onAdd: async (kind: string) => { state.additions.push(kind); },+ onListInput: async (input: import("./listInput").ListMindmapListInput) => { state.listInputs.push(input); },isPanTarget: (event: PointerEvent) => event.target === state.panTarget,onFinish: () => state.finished++,onUndo: noop,@@ -219,7 +221,7 @@ const browserCases = async (sourceCode: string, css: string, cleanupSource: stri};window.siyuan = {languages: {listMindmapStale: "Content changed", listMindmapUnsupported: "Unsupported"},- config: {keymap: {editor: {+ config: {editor: {markdown: {codeBlockMiddleDot: true}}, keymap: {editor: {general: {undo: "undo", redo: "redo",insertBefore: {default: "⇧⌘B", custom: "⇧⌘B"},@@ -232,6 +234,108 @@ const browserCases = async (sourceCode: string, css: string, cleanupSource: stri}}},} as unknown as typeof window.siyuan;+ // 普通段落与软键盘回车走同一节点拆分路径;保留富文本、后续块和原生编辑边界。+ const listParagraph = '<div data-type="NodeParagraph" data-node-id="paragraph"><div contenteditable="true"><span data-type="strong">AlphaBeta</span></div></div>';+ for (const softKeyboard of [false, true]) {+ const current = create(listParagraph + '<div data-type="NodeParagraph" data-node-id="second"><div contenteditable="true">Second</div></div>');+ const editable = current.wysiwyg.querySelector<HTMLElement>('[contenteditable="true"]');+ const range = document.createRange();+ range.setStart(editable.firstChild.firstChild, 5);+ range.collapse(true);+ getSelection().removeAllRanges();+ getSelection().addRange(range);+ const event = softKeyboard ? new InputEvent("beforeinput", {inputType: "insertParagraph", bubbles: true, cancelable: true}) :+ new KeyboardEvent("keydown", {key: "Enter", bubbles: true, cancelable: true});+ editable.dispatchEvent(event);+ check.equal(event.defaultPrevented, true);+ check.equal(current.state.listInputs.length, 1);+ check.equal(current.state.listInputs[0].kind, "split");+ check.match(current.state.listInputs[0].before, /<span data-type="strong">Alpha<\/span>/);+ check.match(current.state.listInputs[0].after, /<span data-type="strong">Beta<\/span>/);+ check.match(current.state.listInputs[0].after, /data-node-id="second"/);+ check.equal(editable.textContent, "AlphaBeta", "planning does not mutate unsaved text");+ await current.remove();+ }+ for (const [key, shift, offset, expected] of [+ ["Enter", false, 0, "before"], ["Enter", false, 9, "split"],+ ["Tab", false, 3, "indent"], ["Tab", true, 3, "outdent"],+ ["Backspace", false, 0, "mergePrevious"], ["Delete", false, 9, "mergeNext"],+ ["Enter", true, 5, undefined], ["Backspace", false, 5, undefined], ["Delete", true, 9, undefined],+ ] as const) {+ const current = create(listParagraph);+ const editable = current.wysiwyg.querySelector<HTMLElement>('[contenteditable="true"]');+ const range = document.createRange();+ range.setStart(editable.firstChild.firstChild, offset);+ range.collapse(true);+ getSelection().removeAllRanges();+ getSelection().addRange(range);+ const event = new KeyboardEvent("keydown", {key, shiftKey: shift, bubbles: true, cancelable: true});+ editable.dispatchEvent(event);+ check.equal(current.state.listInputs[0]?.kind, expected, `${key} shift=${shift} offset=${offset}`);+ check.equal(event.defaultPrevented, !!expected);+ await current.remove();+ }+ for (const boundary of ["code-block", "table", "av", "protyle-wysiwyg__embed", "hint", "composition"]) {+ const current = create(listParagraph);+ const editable = current.wysiwyg.querySelector<HTMLElement>('[contenteditable="true"]');+ const range = document.createRange();+ range.selectNodeContents(editable);+ range.collapse(false);+ getSelection().removeAllRanges();+ getSelection().addRange(range);+ if (boundary === "hint") current.hintElement.classList.remove("fn__none");+ else if (boundary !== "composition") editable.classList.add(boundary);+ const event = new KeyboardEvent("keydown", {key: "Enter", isComposing: boundary === "composition", bubbles: true, cancelable: true});+ editable.dispatchEvent(event);+ check.equal(event.defaultPrevented, false, boundary);+ check.equal(current.state.listInputs.length, 0, boundary);+ await current.remove();+ }+ for (const [inputType, offset, expected] of [+ ["deleteContentBackward", 0, "mergePrevious"], ["deleteContentForward", 9, "mergeNext"],+ ] as const) {+ const current = create(listParagraph);+ const editable = current.wysiwyg.querySelector<HTMLElement>('[contenteditable="true"]');+ const range = document.createRange();+ range.setStart(editable.firstChild.firstChild, offset);+ range.collapse(true);+ getSelection().removeAllRanges();+ getSelection().addRange(range);+ editable.dispatchEvent(new InputEvent("beforeinput", {inputType, bubbles: true, cancelable: true}));+ check.equal(current.state.listInputs[0].kind, expected);+ await current.remove();+ }+ const customized = create(listParagraph);+ const originalChildShortcut = window.siyuan.config.keymap.editor.list.mindmapAddChild.custom;+ window.siyuan.config.keymap.editor.list.mindmapAddChild.custom = "↩";+ const customizedEditable = customized.wysiwyg.querySelector<HTMLElement>('[contenteditable="true"]');+ const customizedRange = document.createRange();+ customizedRange.selectNodeContents(customizedEditable);+ customizedRange.collapse(false);+ getSelection().removeAllRanges();+ getSelection().addRange(customizedRange);+ customizedEditable.dispatchEvent(new KeyboardEvent("keydown", {key: "Enter", bubbles: true, cancelable: true}));+ await until(() => customized.state.additions.length === 1);+ check.deepEqual(customized.state.additions, ["child"], "a configured plain Enter shortcut takes precedence over node splitting");+ check.equal(customized.state.listInputs.length, 0);+ window.siyuan.config.keymap.editor.list.mindmapAddChild.custom = originalChildShortcut;+ await customized.remove();+ for (const marker of ["```js", "~~~go", "···"]) {+ const current = create('<div data-type="NodeParagraph" data-node-id="paragraph"><div contenteditable="true"></div></div>');+ const editable = current.wysiwyg.querySelector<HTMLElement>('[contenteditable="true"]');+ editable.textContent = marker;+ const range = document.createRange();+ range.selectNodeContents(editable);+ range.collapse(false);+ getSelection().removeAllRanges();+ getSelection().addRange(range);+ const event = new KeyboardEvent("keydown", {key: "Enter", bubbles: true, cancelable: true});+ editable.dispatchEvent(event);+ check.equal(event.defaultPrevented, false, "code fences reach the existing Markdown conversion");+ check.equal(current.state.listInputs.length, 0);+ await current.remove();+ }+// 节点编辑器透传未处理的组合快捷键,已消费的编辑操作和组合输入仍保持隔离。const shortcutEditor = create();const received: KeyboardEvent[] = [];@@ -854,7 +958,8 @@ test("list mindmap editor flushes pending input and preserves text across finish}, async () => {const temporary = mkdtempSync(path.join(tmpdir(), "siyuan-mindmap-view-editor-test-"));const script = path.join(temporary, "run.cjs");- const source = transpileModule(readFileSync(path.join(__dirname, "editor.ts"), "utf8")+ const source = transpileModule(["../../wysiwyg/codeBlockEnter.ts", "editor.ts"]+ .map(file => readFileSync(path.join(__dirname, file), "utf8")).join("\n").replace(/^import [\s\S]*?;\r?\n/gm, "").replace(/^export /gm, ""), {compilerOptions: {target: ScriptTarget.ES2021},}).outputText;diff --git a/app/src/protyle/render/listMindmap/editor.ts b/app/src/protyle/render/listMindmap/editor.tsindex 42e88aa307..8568e910c4 100644--- a/app/src/protyle/render/listMindmap/editor.ts+++ b/app/src/protyle/render/listMindmap/editor.ts@@ -20,8 +20,10 @@ import {blockRender} from "../blockRender";import {highlightRender} from "../highlightRender";import {cleanListMindmapHTML} from "./model";import type {ListMindmapNode} from "./model";+import type {ListMindmapListInput} from "./listInput";import {finishListMindmaps} from "./index";import {getUndoFocusContext, restoreFocusContext} from "../../util/selection";+import {canEnterCodeBlock} from "../../wysiwyg/codeBlockEnter";interface ListMindmapEditorOptions {owner: IProtyle;@@ -32,6 +34,7 @@ interface ListMindmapEditorOptions {onSave: (html: string, undoSelection?: Record<string, string>, redoSelection?: Record<string, string>) => Promise<boolean>;onResize: () => void;onAdd: (kind: "child" | "sibling") => Promise<void>;+ onListInput: (input: ListMindmapListInput, selection?: Record<string, string>) => Promise<void>;onFinish: () => void;onUndo: (redo: boolean, selection?: Record<string, string>) => void;isPanTarget?: (event: PointerEvent) => boolean;@@ -103,6 +106,53 @@ const matchesCustomizedEditorShortcut = (event: KeyboardEvent) => {return matched;};+const getListMindmapListInput = (wysiwyg: HTMLElement, range: Range, key: string, shift = false): ListMindmapListInput => {+ const anchor = range?.startContainer;+ const element = anchor instanceof Element ? anchor : anchor?.parentElement;+ const editable = element?.closest<HTMLElement>('[contenteditable="true"]');+ const block = editable?.parentElement;+ if (!block || block.parentElement !== wysiwyg || !editable.contains(range.endContainer) ||+ !["NodeParagraph", "NodeHeading"].includes(block.dataset.type)) {+ return;+ }+ const html = cleanListMindmapHTML(wysiwyg.innerHTML);+ if (key === "Tab") {+ return {kind: shift ? "outdent" : "indent", html};+ }+ const before = range.cloneRange();+ before.selectNodeContents(editable);+ before.setEnd(range.startContainer, range.startOffset);+ const after = range.cloneRange();+ after.selectNodeContents(editable);+ after.setStart(range.endContainer, range.endOffset);+ const empty = (range: Range) => {+ const fragment = range.cloneContents();+ return !fragment.textContent.replace(/\u200b/g, "") && !fragment.querySelector("img, br, [data-type='inline-math']");+ };+ if (key === "Backspace" && range.collapsed && block === wysiwyg.firstElementChild && empty(before)) {+ return {kind: "mergePrevious", html};+ }+ if (key === "Delete" && range.collapsed && block === wysiwyg.lastElementChild && empty(after)) {+ return {kind: "mergeNext", html};+ }+ if (key !== "Enter" || shift || block !== wysiwyg.firstElementChild || block.dataset.type !== "NodeParagraph") {+ return;+ }+ if (canEnterCodeBlock(editable, before.toString().length, window.siyuan.config.editor.markdown.codeBlockMiddleDot !== false)) {+ return;+ }+ if (range.collapsed && empty(before) && !empty(after)) {+ return {kind: "before", html};+ }+ const prefix = block.cloneNode(true) as HTMLElement;+ prefix.querySelector('[contenteditable="true"]').replaceChildren(before.cloneContents());+ const suffix = genEmptyElement(false, false);+ suffix.querySelector('[contenteditable="true"]').replaceChildren(after.cloneContents());+ const following = Array.from(wysiwyg.children).slice(1).map(block => block.outerHTML).join("");+ return {kind: "split", html, before: cleanListMindmapHTML(prefix.outerHTML),+ after: cleanListMindmapHTML(suffix.outerHTML + following)};+};+// 编辑器挂载到节点内容区,预览与编辑沿用同一尺寸和排版。export const openListMindmapEditor = (options: ListMindmapEditorOptions) => {const {owner, node, host} = options;@@ -383,6 +433,44 @@ export const openListMindmapEditor = (options: ListMindmapEditorOptions) => {};setMobileToolbarUndo(fragment.protyle, owner, undo);const signal = events.signal;+ const listInput = (event: KeyboardEvent | InputEvent, key: string, shift = false) => {+ if (event.defaultPrevented || event.isComposing || composing || finished || closing || !options.canEdit() ||+ !fragment.hintElement.classList.contains("fn__none") ||+ !fragment.protyle.toolbar.element.classList.contains("fn__none") ||+ !fragment.protyle.toolbar.subElement.classList.contains("fn__none") ||+ !(event.target instanceof Element) || event.target.closest(+ "input, textarea, select, button, .protyle-wysiwyg__embed, .av, .code-block, .table") ||+ event.target.closest(".protyle-wysiwyg") !== fragment.wysiwyg) {+ return;+ }+ const selection = getSelection();+ const input = selection?.rangeCount && getListMindmapListInput(fragment.wysiwyg, selection.getRangeAt(0), key, shift);+ if (!input) {+ return;+ }+ event.preventDefault();+ event.stopImmediatePropagation();+ if (addingNode || event instanceof KeyboardEvent && event.repeat) {+ return;+ }+ addingNode = true;+ input.html = retainIndependentBlocks(input.html, node);+ if (input.after) {+ input.after = retainIndependentBlocks(input.after, node);+ }+ void options.onListInput(input, captureSelection()).catch(error => console.error(error)).finally(() => {+ addingNode = false;+ });+ };+ host.addEventListener("beforeinput", event => {+ if (event.inputType === "insertParagraph") {+ listInput(event, "Enter");+ } else if (event.inputType === "deleteContentBackward") {+ listInput(event, "Backspace");+ } else if (event.inputType === "deleteContentForward") {+ listInput(event, "Delete");+ }+ }, {capture: true, signal});host.addEventListener("beforeinput", captureBeforeChange, {capture: true, signal});host.addEventListener("compositionstart", captureBeforeChange, {capture: true, signal});host.addEventListener("pointerdown", captureBeforeChange, {capture: true, signal});@@ -426,6 +514,13 @@ export const openListMindmapEditor = (options: ListMindmapEditorOptions) => {const listKeymap = window.siyuan.config.keymap.editor.list;const kind = listKeymap?.mindmapAddSibling && matchHotKey(listKeymap.mindmapAddSibling, event) ? "sibling" :listKeymap?.mindmapAddChild && matchHotKey(listKeymap.mindmapAddChild, event) ? "child" : undefined;+ if (!event.ctrlKey && !event.metaKey && !event.altKey && (!event.shiftKey || event.key === "Tab") &&+ !kind && ["Enter", "Tab", "Backspace", "Delete"].includes(event.key) && !matchesCustomizedEditorShortcut(event)) {+ listInput(event, event.key, event.shiftKey);+ if (event.defaultPrevented) {+ return;+ }+ }if (matchHotKey(keymap.undo, event) || matchHotKey(keymap.redo, event)) {event.preventDefault();event.stopImmediatePropagation();diff --git a/app/src/protyle/render/listMindmap/index.ts b/app/src/protyle/render/listMindmap/index.tsindex 4d117988a9..2edda4de64 100644--- a/app/src/protyle/render/listMindmap/index.ts+++ b/app/src/protyle/render/listMindmap/index.ts@@ -31,6 +31,8 @@ import {} from "./model";import {prepareListMindmapConversion} from "./conversion";import type {ListMindmapMetadata, ListMindmapModel} from "./model";+import {applyListMindmapListInput, getListMindmapListInputTarget} from "./listInput";+import type {ListMindmapListInput} from "./listInput";import {getListMindmapElements, registerListMindmapRoot, registerListMindmapView} from "./render";import {syncListMindmapHeight} from "./height";import {bindListMindmapResize} from "./resize";@@ -872,6 +874,47 @@ class ListMindmapController {}}+ private async listInput(id: string, input: ListMindmapListInput, selection?: Record<string, string>) {+ const request = this.editRequest;+ const rootID = this.owner.block.rootID;+ if (input.kind !== "split" && input.kind !== "before" &&+ !getListMindmapListInputTarget(this.model.nodes.get(id), input.kind)) {+ return;+ }+ if (!canEdit(this.owner, this.list) || this.activeEditor && !await this.activeEditor.finish() ||+ request !== this.editRequest || rootID !== this.owner.block.rootID || this.disposed || !canEdit(this.owner, this.list)) {+ return;+ }+ const source = this.list.cloneNode(true) as HTMLElement;+ const node = readListMindmap(source).nodes.get(id);+ if (!node?.element) {+ return;+ }+ let item: HTMLElement;+ if (input.kind === "split" || input.kind === "before") {+ item = genListItemElement(node.element, 0, false);+ if (source.dataset.type === "NodeMindmap") {+ item.dataset.type = "NodeMindmapItem";+ item.classList.replace("li", "mindmap-item");+ }+ }+ const result = applyListMindmapListInput(source, id, input, item);+ const before = cleanListMindmapHTML(this.list.outerHTML);+ if (!result || !await this.change(() => {+ if (cleanListMindmapHTML(this.list.outerHTML) !== before) {+ return false;+ }+ this.replaceClipboardSource(source);+ }, false, result.id, {undo: selection, redo: result.selection || selection})) {+ return;+ }+ this.view.focusNode(result.id);+ const host = this.view.getContentHost(result.id);+ if (host) {+ await this.edit(result.id, host, undefined, undefined, result.selection || selection);+ }+ }+private async edit(id: string, host: HTMLElement, replaceFirstParagraph?: string, clipboard?: IClipboardData,selection?: Record<string, string>, guard?: () => boolean) {if (guard && !guard()) {@@ -897,6 +940,7 @@ class ListMindmapController {onSave: (html, undo, redo) => this.change(() => replaceListMindmapContent(this.list, id, html), true, id, {undo, redo}),onResize: () => this.view.refreshLayout(),onAdd: kind => this.add(id, kind),+ onListInput: (input, selection) => this.listInput(id, input, selection),isPanTarget: event => this.view.isPanTarget(event),onFinish: () => {if (this.activeEditor !== editor) {diff --git a/app/src/protyle/render/listMindmap/listInput.test.ts b/app/src/protyle/render/listMindmap/listInput.test.tsnew file mode 100644index 0000000000..ccc1d6999d--- /dev/null+++ b/app/src/protyle/render/listMindmap/listInput.test.ts@@ -0,0 +1,176 @@+import * as assert from "node:assert/strict";+import {execFile} from "node:child_process";+import {mkdtempSync, readFileSync, rmSync, writeFileSync} from "node:fs";+import {tmpdir} from "node:os";+import * as path from "node:path";+import test from "node:test";+import {promisify} from "node:util";+import {createSourceFile, isClassDeclaration, ScriptTarget, transpileModule} from "typescript";++const browserCases = async (source: string) => {+ const check = require("node:assert/strict");+ const history: {before: string; after: string; undo: Record<string, string>; redo: Record<string, string>}[] = [];+ const noop = () => {};+ const lute = Lute.New();+ lute.SetKramdownIAL(true);+ lute.SetProtyleWYSIWYG(true);+ const holder = document.createElement("div");+ document.body.append(holder);+ let editable = true;+ const constants = {CUSTOM_SY_LIST_MINDMAP: "custom-sy-list-mindmap",+ CUSTOM_SY_LIST_MINDMAP_DATA: "custom-sy-list-mindmap-data", CUSTOM_SY_CODE_TAB_SPACES: "custom-sy-code-tab-spaces"};+ const blockDOM = (markdown: string) => {+ const element = document.createElement("div");+ element.innerHTML = lute.Md2BlockDOM(markdown);+ return element;+ };+ const dependencies = {Constants: constants, canEdit: () => editable, showMessage: (message: string) => check.fail(message),+ disposeCustomBlocksInElement: noop, processRender: noop, highlightRender: noop, avRender: noop, blockRender: noop,+ genListItemElement: () => blockDOM("- New\n").firstElementChild.firstElementChild,+ updateTransaction: (_owner: unknown, list: HTMLElement, before: string, undo: Record<string, string>,+ extra: {context: Record<string, string>}) => history.push({before, after: list.outerHTML, undo, redo: extra.context}),+ };+ const api = new Function(...Object.keys(dependencies), source ++ "; return {readListMindmap, cleanListMindmapHTML, applyListMindmapListInput, retagMindmapBranch, replaceListMindmapContent, InputController};")(...Object.values(dependencies));+ for (const legacy of [false, true]) {+ holder.replaceChildren(...Array.from(blockDOM("- Alpha\n - Child\n- Beta\n - Grandchild\n- Gamma\n").children));+ const list = holder.firstElementChild as HTMLElement;+ if (!legacy) api.retagMindmapBranch(list, true);+ const read = () => api.readListMindmap(list);+ const [a, b, c] = Array.from(list.children).filter((item: HTMLElement) => item.dataset.nodeId)+ .map((item: HTMLElement) => item.dataset.nodeId);+ const html = (id: string) => read().nodes.get(id).contentBlocks.map((block: HTMLElement) =>+ api.cleanListMindmapHTML(block.outerHTML)).join("");+ const original = list.outerHTML;+ const descendants = read().nodes.get(b).children.map((node: {id: string}) => node.id);+ check.equal(api.applyListMindmapListInput(list, b, {kind: "indent", html: html(b)}).id, b);+ check.equal(read().nodes.get(b).parentId, a);+ check.deepEqual(read().nodes.get(b).children.map((node: {id: string}) => node.id), descendants);+ check.equal(api.applyListMindmapListInput(list, b, {kind: "outdent", html: html(b)}).id, b);+ check.equal(list.outerHTML, original, "indent/outdent preserve content, IDs and branch order");+ for (const [id, kind] of [[a, "indent"], [a, "outdent"], [a, "mergePrevious"], [c, "mergeNext"]]) {+ check.equal(api.applyListMindmapListInput(list, id, {kind, html: html(id)}), undefined);+ }+ check.equal(api.applyListMindmapListInput(list, b, {kind: "split", html: "stale"}), undefined);+ check.equal(list.outerHTML, original, "invalid boundaries and stale text do not mutate data");+ const controller = new api.InputController();+ const edits: {id: string; selection: Record<string, string>}[] = [];+ let focused = b;+ Object.assign(controller, {list, owner: {block: {rootID: "document"}, wysiwyg: {element: holder}}, disposed: false,+ model: read(), view: {getSelectedId: () => focused, focusNode: (id: string) => { focused = id; },+ getContentHost: () => holder},+ refresh: () => { controller.model = read(); },+ edit: async (id: string, _host: HTMLElement, _replace: string, _clipboard: unknown, selection: Record<string, string>) => {+ edits.push({id, selection});+ }});+ const paragraph = read().nodes.get(b).contentBlocks[0].cloneNode(true) as HTMLElement;+ paragraph.querySelector('[contenteditable="true"]').textContent = "Be";+ const after = blockDOM("ta\n\n> Rich content\n");+ const extraID = after.lastElementChild.getAttribute("data-node-id");+ const selection = {undoFocusId: paragraph.dataset.nodeId, undoFocusStart: "2", undoFocusEnd: "2"};+ let finished = 0;+ controller.activeEditor = {finish: async () => { finished++; controller.activeEditor = undefined; return true; }};+ await controller.listInput(b, {kind: "split", html: html(b), before: paragraph.outerHTML, after: after.innerHTML}, selection);+ check.equal(finished, 1);+ const splitID = focused;+ check.notEqual(splitID, b);+ check.equal(read().nodes.get(b).contentBlocks[0].querySelector('[contenteditable="true"]').textContent, "Be");+ check.match(read().nodes.get(splitID).element.textContent, /ta.*Rich content/s);+ check.equal(edits.at(-1).selection.undoFocusStart, "0");+ check.deepEqual(JSON.parse(history.at(-1).undo.undoFocusMindmapSelection), selection);+ check.equal(history.at(-1).redo.undoFocusId, splitID);+ const transactionCount = history.length;+ await controller.listInput(splitID, {kind: "indent", html: html(splitID)}, edits.at(-1).selection);+ check.equal(read().nodes.get(splitID).parentId, b);+ await controller.listInput(splitID, {kind: "outdent", html: html(splitID)}, edits.at(-1).selection);+ check.equal(read().nodes.get(splitID).parentId, read().nodes.get(b).parentId);+ await controller.listInput(splitID, {kind: "mergePrevious", html: html(splitID)}, edits.at(-1).selection);+ check.equal(history.length, transactionCount+3, "each structural edit is one transaction");+ check.equal(read().nodes.has(splitID), false);+ check.ok(read().nodes.get(b).contentBlocks.some((block: HTMLElement) => block.dataset.nodeId === extraID));+ const merged = history.at(-1);+ const restore = (html: string) => { const dom = document.createElement("div"); dom.innerHTML = html;+ controller.replaceClipboardSource(dom.firstElementChild); controller.refresh(); };+ restore(merged.before);+ check.equal(read().nodes.has(splitID), true, "undo restores the separate node and all body IDs");+ restore(merged.after);+ check.equal(read().nodes.has(splitID), false, "redo restores the merged body");+ const moved = read().nodes.get(b).children.map((node: {id: string}) => node.id);+ await controller.listInput(a, {kind: "mergeNext", html: html(a)});+ check.equal(read().nodes.has(b), false);+ moved.forEach((id: string) => check.equal(read().nodes.get(id).parentId, a, "merge preserves descendant branches"));+ check.ok(read().nodes.get(a).contentBlocks.some((block: HTMLElement) => block.dataset.nodeId === extraID));+ check.equal(read().nodes.has(c), true);+ const fresh = blockDOM("- Before\n").firstElementChild;+ if (!legacy) api.retagMindmapBranch(fresh, true);+ const inserted = api.applyListMindmapListInput(list, a, {kind: "before", html: html(a)}, fresh.firstElementChild);+ check.equal(read().nodes.get(a).element.previousElementSibling.dataset.nodeId, inserted.id);+ const noChange = list.outerHTML;+ controller.model = read();+ const count = history.length;+ await controller.listInput(c, {kind: "split", html: "stale", before: "stale", after: "stale"});+ editable = false;+ await controller.listInput(c, {kind: "before", html: html(c)});+ editable = true;+ controller.activeEditor = {finish: async () => false};+ await controller.listInput(c, {kind: "before", html: html(c)});+ controller.activeEditor = undefined;+ for (const interrupt of ["editor", "document"]) {+ controller.activeEditor = {finish: async () => {+ if (interrupt === "editor") controller.editRequest = (controller.editRequest || 0) + 1;+ else controller.owner.block.rootID = "other-document";+ controller.activeEditor = undefined;+ return true;+ }};+ await controller.listInput(c, {kind: "before", html: html(c)});+ controller.owner.block.rootID = "document";+ }+ check.equal(history.length, count);+ check.equal(list.outerHTML, noChange, "failed saves, stale requests and readonly mode preserve source");+ const canonical = blockDOM("");+ canonical.innerHTML = lute.SpinBlockDOM(api.cleanListMindmapHTML(list.outerHTML));+ check.ok(api.readListMindmap(canonical.firstElementChild).nodes.has(c), "Lute preserves the resulting hierarchy");+ }+ holder.remove();+ return "Mindmap list input cases passed";+};++test("mindmap list input preserves rich blocks, branch identity, transaction focus and undo snapshots", {+ skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,+ timeout: 30000,+}, async () => {+ const compile = (source: string) => transpileModule(source.replace(/^import [\s\S]*?;\r?\n/gm, "")+ .replace(/^export /gm, ""), {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;+ const sourceFile = createSourceFile("index.ts", readFileSync(path.join(__dirname, "index.ts"), "utf8"), ScriptTarget.Latest, true);+ const controller = sourceFile.statements.find(isClassDeclaration);+ const names = ["listInput", "change", "replaceClipboardSource", "replaceSourceChildren"];+ const methods = controller.members.filter(item => names.includes(item.name?.getText(sourceFile)));+ assert.equal(methods.length, names.length);+ const source = ["../../wysiwyg/listContext.ts", "summary.ts", "connectors.ts", "appearance.ts", "model.ts", "listInput.ts"]+ .map(name => compile(readFileSync(path.join(__dirname, name), "utf8"))).join("\n") ++ compile(`class InputController {${methods.map(item => item.getText(sourceFile)).join("\n")}}`);+ const temporary = mkdtempSync(path.join(tmpdir(), "siyuan-mindmap-list-input-"));+ const script = path.join(temporary, "run.cjs");+ const code = `const __name = value => value; (${browserCases.toString()})(${JSON.stringify(source)})`;+ writeFileSync(script, `const {app, BrowserWindow} = require("electron");+app.setPath("userData", ${JSON.stringify(path.join(temporary, "profile"))});+app.whenReady().then(async () => {+ const win = new BrowserWindow({show: false, webPreferences: {nodeIntegration: true, contextIsolation: false, offscreen: true}});+ try {+ await win.loadURL("data:text/html,<html><body></body></html>");+ await win.webContents.executeJavaScript(${JSON.stringify(readFileSync(path.resolve(__dirname, "../../../../stage/protyle/js/lute/lute.min.js"), "utf8"))});+ console.log(await win.webContents.executeJavaScript(${JSON.stringify(code)}));+ win.destroy(); app.exit(0);+ } catch (error) { console.error(error); win.destroy(); app.exit(1); }+});`, "utf8");+ const env = {...process.env};+ delete env.ELECTRON_RUN_AS_NODE;+ try {+ const result = await promisify(execFile)(require("electron") as unknown as string, [script], {env, timeout: 25000, windowsHide: true});+ assert.match(result.stdout, /Mindmap list input cases passed/);+ } finally {+ if (path.dirname(path.resolve(temporary)) === path.resolve(tmpdir()) && path.basename(temporary).startsWith("siyuan-mindmap-list-input-")) {+ rmSync(temporary, {recursive: true, force: true});+ }+ }+});diff --git a/app/src/protyle/render/listMindmap/listInput.ts b/app/src/protyle/render/listMindmap/listInput.tsnew file mode 100644index 0000000000..89958913a4--- /dev/null+++ b/app/src/protyle/render/listMindmap/listInput.ts@@ -0,0 +1,75 @@+import {addListMindmapNode, cleanListMindmapHTML, deleteListMindmapNode, moveListMindmapNode, readListMindmap, replaceListMindmapContent} from "./model";+import type {ListMindmapNode} from "./model";++export interface ListMindmapListInput {+ kind: "split" | "before" | "indent" | "outdent" | "mergePrevious" | "mergeNext";+ html: string;+ before?: string;+ after?: string;+}++export const getListMindmapListInputTarget = (node: ListMindmapNode, kind: ListMindmapListInput["kind"]) => {+ const element = node?.element;+ const isItem = (element?: Element) => element &&+ ["NodeListItem", "NodeMindmapItem"].includes(element.getAttribute("data-type"));+ if (!element) {+ return;+ }+ const target = kind === "outdent" ? element.parentElement?.parentElement :+ kind === "mergeNext" ? element.nextElementSibling : element.previousElementSibling;+ return isItem(target) ? target as HTMLElement : undefined;+};++// 调用方在克隆的完整源树上规划,再以一次可撤销事务替换正文。+export const applyListMindmapListInput = (list: HTMLElement, id: string, input: ListMindmapListInput,+ item?: HTMLElement) => {+ const model = readListMindmap(list);+ const node = model.nodes.get(id);+ if (!node?.element || node.contentBlocks.map(block => cleanListMindmapHTML(block.outerHTML)).join("") !== input.html) {+ return;+ }+ const target = getListMindmapListInputTarget(node, input.kind);+ const focus = (id: string, block?: Element) => ({id, selection: block ? {+ undoFocusId: block.getAttribute("data-node-id"), undoFocusStart: "0", undoFocusEnd: "0",+ } : undefined});+ if (input.kind === "indent" || input.kind === "outdent") {+ if (target && moveListMindmapNode(list, id, target.dataset.nodeId, input.kind === "indent" ? "child" : "after")) {+ return focus(id);+ }+ return;+ }+ if (input.kind === "split" || input.kind === "before") {+ if (!item) {+ return;+ }+ if (input.kind === "split") {+ if (!input.before || !input.after || !replaceListMindmapContent(list, id, input.before)) {+ return;+ }+ const template = list.ownerDocument.createElement("template");+ template.innerHTML = input.after;+ const paragraph = Array.from(item.children).find(child => child.hasAttribute("data-node-id"));+ paragraph.replaceWith(...Array.from(template.content.children));+ }+ if (addListMindmapNode(list, id, input.kind === "before" ? "before" : "after", item)) {+ return focus(item.dataset.nodeId, item.querySelector("[data-node-id]"));+ }+ return;+ }+ if (!target) {+ return;+ }+ const destination = input.kind === "mergePrevious" ? target : node.element;+ const source = input.kind === "mergePrevious" ? node.element : target;+ const sourceNode = model.nodes.get(source.dataset.nodeId);+ const content = sourceNode.contentBlocks;+ const boundary = Array.from(destination.children).find(child =>+ child.getAttribute("data-type") === (list.dataset.type === "NodeMindmap" ? "NodeMindmap" : "NodeList") ||+ child.classList.contains("protyle-attr"));+ content.forEach(block => destination.insertBefore(block, boundary || null));+ sourceNode.children.forEach(child => moveListMindmapNode(list, child.id, destination.dataset.nodeId, "child"));+ if (deleteListMindmapNode(list, source.dataset.nodeId)) {+ return focus(destination.dataset.nodeId, content[0]);+ }+};+