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: Convert selected mind maps with list shortcuts https://github.com/siyuan-note/siyuan/issues/20053
Danielee1ddbac2de1
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 08431838d5..3e20b23c43 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": "20261002013053"+ "updated": "20261002201736"},"Children": [{@@ -10113,7 +10113,7 @@"HeadingLevel": 3,"Properties": {"id": "20210106154319-d0mxz1p",- "updated": "20260811122156"+ "updated": "20261002201736"},"Children": [{@@ -10137,7 +10137,7 @@"Properties": {"colgroup": "||","id": "20210106154319-v6ksqnu",- "updated": "20260811122156"+ "updated": "20261002201736"},"Children": [{@@ -11386,6 +11386,10 @@{"Type": "NodeText","Data": "See below for related shortcuts"+ },+ {+ "Type": "NodeText",+ "Data": "; the configured shortcut also converts a selected mind map block to this list type"}]}@@ -11431,6 +11435,10 @@{"Type": "NodeText","Data": "See below for related shortcuts"+ },+ {+ "Type": "NodeText",+ "Data": "; the configured shortcut also converts a selected mind map block to this list type"}]}@@ -11503,6 +11511,10 @@{"Type": "NodeText","Data": "See below for related shortcuts"+ },+ {+ "Type": "NodeText",+ "Data": "; the configured shortcut also converts a selected mind map block to this list type"}]}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 d0aee26a61..99cdd8ece2 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": "20261002013053"+ "updated": "20261002201736"},"Children": [{@@ -10113,7 +10113,7 @@"HeadingLevel": 3,"Properties": {"id": "20210102174148-tq925jm",- "updated": "20260811122156"+ "updated": "20261002201736"},"Children": [{@@ -10133,7 +10133,7 @@"Properties": {"colgroup": "||","id": "20210102174148-snb76bj",- "updated": "20260811122156"+ "updated": "20261002201736"},"Children": [{@@ -11365,6 +11365,10 @@{"Type": "NodeText","Data": "相关快捷键参见下文"+ },+ {+ "Type": "NodeText",+ "Data": ";配置快捷键后,也可将选中的思维导图块转换为对应列表"}]}@@ -11410,6 +11414,10 @@{"Type": "NodeText","Data": "相关快捷键参见下文"+ },+ {+ "Type": "NodeText",+ "Data": ";配置快捷键后,也可将选中的思维导图块转换为对应列表"}]}@@ -11491,6 +11499,10 @@{"Type": "NodeText","Data": "相关快捷键参见下文"+ },+ {+ "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.syindex 52e07b65c9..85560904ba 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": "20261002013053"+ "updated": "20261002201736"},"Children": [{@@ -10102,7 +10102,7 @@"HeadingLevel": 3,"Properties": {"id": "20211226122652-8191vgw",- "updated": "20260811122156"+ "updated": "20261002201736"},"Children": [{@@ -10122,7 +10122,7 @@"Properties": {"colgroup": "||","id": "20211226122652-v6as45b",- "updated": "20260811122156"+ "updated": "20261002201736"},"Children": [{@@ -11377,6 +11377,10 @@{"Type": "NodeText","Data": "相關快捷鍵參見下文"+ },+ {+ "Type": "NodeText",+ "Data": ";設定快速鍵後,也可將選取的心智圖區塊轉換為對應列表"}]}@@ -11422,6 +11426,10 @@{"Type": "NodeText","Data": "相關快捷鍵參見下文"+ },+ {+ "Type": "NodeText",+ "Data": ";設定快速鍵後,也可將選取的心智圖區塊轉換為對應列表"}]}@@ -11503,6 +11511,10 @@{"Type": "NodeText","Data": "相關快捷鍵參見下文"+ },+ {+ "Type": "NodeText",+ "Data": ";設定快速鍵後,也可將選取的心智圖區塊轉換為對應列表"}]}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 c60a19e3b8..27693965f5 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": "20261002013053"+ "updated": "20261002201736"},"Children": [{@@ -10039,7 +10039,7 @@"Properties": {"ID": "20240530101000-qf3oj4u","id": "20240530101000-zy0pmo3",- "updated": "20260811122156"+ "updated": "20261002201736"},"Children": [{@@ -10069,7 +10069,7 @@"Properties": {"colgroup": "||","id": "20240530101000-5be9vw0",- "updated": "20260811122156"+ "updated": "20261002201736"},"Children": [{@@ -11314,6 +11314,10 @@{"Type": "NodeText","Data": "関連するショートカットは以下をご覧ください"+ },+ {+ "Type": "NodeText",+ "Data": "。設定したショートカットで、選択したマインドマップブロックを対応するリストに変換することもできます"}]}@@ -11359,6 +11363,10 @@{"Type": "NodeText","Data": "関連するショートカットは以下をご覧ください"+ },+ {+ "Type": "NodeText",+ "Data": "。設定したショートカットで、選択したマインドマップブロックを対応するリストに変換することもできます"}]}@@ -11431,6 +11439,10 @@{"Type": "NodeText","Data": "関連するショートカットは以下をご覧ください"+ },+ {+ "Type": "NodeText",+ "Data": "。設定したショートカットで、選択したマインドマップブロックを対応するリストに変換することもできます"}]}diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.tsindex 9513eb562e..eb623deae3 100644--- a/app/src/protyle/gutter/index.ts+++ b/app/src/protyle/gutter/index.ts@@ -1805,6 +1805,7 @@ export class Gutter {{menuId: "check", icon: "iconCheck", label: "check", type: "UL2TL"},].forEach(target => turnIntoSubmenu.push(this.turnsOneInto({...target, id, protyle, nodeElement, label: window.siyuan.languages[target.label],+ accelerator: window.siyuan.config.keymap.editor.insert[target.label].custom,})));} else if (listSubtype === "o") {turnIntoSubmenu.push(this.turnsOneInto({diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.tsindex 7c5fff7ebc..b089a36e5e 100644--- a/app/src/protyle/wysiwyg/keydown.ts+++ b/app/src/protyle/wysiwyg/keydown.ts@@ -2289,7 +2289,15 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {const targetSubtype: TListSubtype = isMatchCheck ? "t" : (isMatchList ? "u" : "o");const listContext = hasBlockSelection ? undefined :getListContext(selectsElement[0], protyle.wysiwyg.element);- if (listContext) {+ if (type === "NodeMindmap" || type === "NodeList" &&+ selectsElement[0].getAttribute(Constants.CUSTOM_SY_LIST_MINDMAP) === "1") {+ turnsOneInto({+ protyle,+ nodeElement: selectsElement[0],+ id: selectsElement[0].dataset.nodeId,+ type: isMatchCheck ? "UL2TL" : (isMatchList ? "OL2UL" : "UL2OL"),+ });+ } else if (listContext) {const isListItemFocused = Boolean(protyle.block.showAll &&protyle.block.id === listContext.listItemElement.dataset.nodeId);const action = getListShortcutAction(listContext, targetSubtype,diff --git a/app/src/protyle/wysiwyg/listShortcut.test.ts b/app/src/protyle/wysiwyg/listShortcut.test.tsnew file mode 100644index 0000000000..4cea8766ca--- /dev/null+++ b/app/src/protyle/wysiwyg/listShortcut.test.ts@@ -0,0 +1,64 @@+import * as assert from "node:assert/strict";+import {readFileSync} from "node:fs";+import {test} from "node:test";+import {runInNewContext} from "node:vm";+import {ScriptTarget, transpileModule} from "typescript";+import {getListConversionType, shouldIgnoreListShortcut} from "./listContext";++const source = readFileSync("src/protyle/wysiwyg/keydown.ts", "utf8");+const start = source.indexOf(" const isMatchList =");+const end = source.indexOf(" if (matchHotKey(window.siyuan.config.keymap.editor.insert.table", start);+assert.ok(start >= 0 && end > start);+const compiled = transpileModule(`(async () => {${source.slice(start, end)}})()`, {+ compilerOptions: {target: ScriptTarget.ES2021},+}).outputText;++const runShortcut = async (type: string, subtype: string, key: string, legacy = false, embedded = false) => {+ const selected = {+ dataset: {type, subtype, nodeId: "selected"},+ getAttribute: (name: string) => name === "custom-sy-list-mindmap" && legacy ? "1" : null,+ };+ const calls: {type: string, nodeElement?: unknown}[] = [];+ const insertions: string[] = [];+ let prevented = false;+ const context = {+ window: {siyuan: {config: {keymap: {editor: {insert: {list: "list", check: "check", "ordered-list": "ordered-list", quote: "quote"}}}}}},+ Constants: {CUSTOM_SY_LIST_MINDMAP: "custom-sy-list-mindmap"},+ matchHotKey: (binding: string) => binding === key,+ event: {preventDefault: () => prevented = true, stopPropagation() {}},+ protyle: {wysiwyg: {element: {querySelectorAll: () => [selected]}},+ hint: {fillCommand: (value: string) => insertions.push(value)}},+ nodeElement: {dataset: {type: "NodeParagraph", nodeId: "following-paragraph"}},+ range: {}, isCrossBlock: false, selectText: "",+ isProtyleListItemFragment: () => false,+ isInEmbedBlock: () => embedded,+ shouldIgnoreListShortcut, getListConversionType,+ turnsOneInto: (options: {type: string, nodeElement?: unknown}) => calls.push(options),+ Lute: {Caret: "caret"},+ };+ await runInNewContext(compiled, context);+ return {selected, calls, insertions, prevented};+};++test("list shortcuts convert the selected mindmap instead of inserting at the retained caret", async () => {+ for (const legacy of [false, true]) {+ for (const subtype of ["u", "o", "t"]) {+ for (const [key, type] of [["list", "OL2UL"], ["ordered-list", "UL2OL"], ["check", "UL2TL"]]) {+ const result = await runShortcut(legacy ? "NodeList" : "NodeMindmap", subtype, key, legacy);+ assert.equal(result.calls.length, 1);+ assert.equal(result.calls[0].type, type);+ assert.equal(result.calls[0].nodeElement, result.selected);+ assert.deepEqual(result.insertions, []);+ assert.equal(result.prevented, true);+ }+ }+ }+});++test("ordinary list cancellation and embedded mindmap protection remain intact", async () => {+ const ordinary = await runShortcut("NodeList", "u", "list");+ assert.equal(ordinary.calls[0].type, "CancelList");+ const embedded = await runShortcut("NodeMindmap", "u", "list", false, true);+ assert.deepEqual(embedded.calls, []);+ assert.deepEqual(embedded.insertions, []);+});