Skip to content

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

:sparkles: Add an unassigned shortcut for mind map insertion and conversion https://github.com/siyuan-note/siyuan/issues/20051

Daniela8d358e3bc56
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 d4a05ead1b..fef4490d08 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": "20261002202032"
+ "updated": "20261002202250"
},
"Children": [
{
@@ -10119,7 +10119,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20210106154319-d0mxz1p",
- "updated": "20261002201736"
+ "updated": "20261002202250"
},
"Children": [
{
@@ -10143,7 +10143,7 @@
"Properties": {
"colgroup": "||",
"id": "20210106154319-v6ksqnu",
- "updated": "20261002201736"
+ "updated": "20261002202250"
},
"Children": [
{
@@ -11526,6 +11526,65 @@
}
]
},
+ {
+ "Type": "NodeTableRow",
+ "Data": "tr",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "Mind map block"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "Unassigned"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "Insert a mind map, or convert the selected list or the list containing the caret; configure in "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Settings"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Keymap"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Editor"
+ }
+ ]
+ }
+ ]
+ },
{
"Type": "NodeTableRow",
"Data": "tr",
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 0fc2739e1d..1a3b8e0f72 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": "20261002202032"
+ "updated": "20261002202250"
},
"Children": [
{
@@ -10119,7 +10119,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20210102174148-tq925jm",
- "updated": "20261002201736"
+ "updated": "20261002202250"
},
"Children": [
{
@@ -10139,7 +10139,7 @@
"Properties": {
"colgroup": "||",
"id": "20210102174148-snb76bj",
- "updated": "20261002201736"
+ "updated": "20261002202250"
},
"Children": [
{
@@ -11514,6 +11514,69 @@
}
]
},
+ {
+ "Type": "NodeTableRow",
+ "Data": "tr",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "思维导图块"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "未绑定"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "插入思维导图,或将选中的列表、光标所在列表转换为思维导图;可在 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "设置"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "快捷键"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "编辑器"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 中配置"
+ }
+ ]
+ }
+ ]
+ },
{
"Type": "NodeTableRow",
"Data": "tr",
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 ad7ba0b8de..d5f1492e82 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": "20261002202032"
+ "updated": "20261002202250"
},
"Children": [
{
@@ -10108,7 +10108,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20211226122652-8191vgw",
- "updated": "20261002201736"
+ "updated": "20261002202250"
},
"Children": [
{
@@ -10128,7 +10128,7 @@
"Properties": {
"colgroup": "||",
"id": "20211226122652-v6as45b",
- "updated": "20261002201736"
+ "updated": "20261002202250"
},
"Children": [
{
@@ -11526,6 +11526,69 @@
}
]
},
+ {
+ "Type": "NodeTableRow",
+ "Data": "tr",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "心智圖區塊"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "未綁定"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "插入心智圖,或將選取的列表、游標所在列表轉換為心智圖;可在 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "設定"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "快速鍵"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "編輯器"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 中設定"
+ }
+ ]
+ }
+ ]
+ },
{
"Type": "NodeTableRow",
"Data": "tr",
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.sy
index d8be189ec8..a273936e02 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": "20261002202032"
+ "updated": "20261002202250"
},
"Children": [
{
@@ -10045,7 +10045,7 @@
"Properties": {
"ID": "20240530101000-qf3oj4u",
"id": "20240530101000-zy0pmo3",
- "updated": "20261002201736"
+ "updated": "20261002202250"
},
"Children": [
{
@@ -10075,7 +10075,7 @@
"Properties": {
"colgroup": "||",
"id": "20240530101000-5be9vw0",
- "updated": "20261002201736"
+ "updated": "20261002202250"
},
"Children": [
{
@@ -11454,6 +11454,69 @@
}
]
},
+ {
+ "Type": "NodeTableRow",
+ "Data": "tr",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "マインドマップブロック"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "未割り当て"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "マインドマップを挿入、または選択したリストやカーソル位置のリストをマインドマップに変換。"
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "設定"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "ショートカット"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "エディタ"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " で設定できます"
+ }
+ ]
+ }
+ ]
+ },
{
"Type": "NodeTableRow",
"Data": "tr",
diff --git a/app/src/command/insertCommands.test.ts b/app/src/command/insertCommands.test.ts
index 0bd9017235..611d459e7b 100644
--- a/app/src/command/insertCommands.test.ts
+++ b/app/src/command/insertCommands.test.ts
@@ -72,6 +72,7 @@ test("insert commands search and execute existing insertion actions at the saved
assert.ok(registry.list({...context, environment: "browser-mobile"}).some(command => command.id === "core.mobile.insert.template"));
assert.deepEqual(Array.from(registry.get("core.mobile.insert.heading1")?.keymapPath || []), ["editor", "heading", "heading1"]);
assert.deepEqual(Array.from(registry.get("core.mobile.insert.orderedList")?.keymapPath || []), ["editor", "insert", "ordered-list"]);
+ assert.deepEqual(Array.from(registry.get("core.mobile.insert.mindmap")?.keymapPath || []), ["editor", "insert", "mindmap"]);
assert.deepEqual(Array.from(registry.get("core.mobile.insert.ref")?.keymapPath || []), ["editor", "insert", "ref"]);
assert.equal(registry.get("core.mobile.insert.template")?.keymapPath, undefined);
assert.equal(queryCommandPalette(registry, context, "模板")[0].id, "core.mobile.insert.template");
diff --git a/app/src/command/insertCommands.ts b/app/src/command/insertCommands.ts
index 03004037f7..5b1a3567d8 100644
--- a/app/src/command/insertCommands.ts
+++ b/app/src/command/insertCommands.ts
@@ -28,7 +28,7 @@ const BUILTIN_STYLES: Record<string, TBuiltinInlineStyleID> = {
const SPECIAL_LABELS: Record<string, string> = {
html: "HTML", flowChart: "Flow Chart", graph: "Graph", mermaid: "Mermaid", UML: "UML",
};
-const INSERT_KEYMAP_IDS = new Set(["ref", "list", "orderedList", "check", "quote", "code", "table"]);
+const INSERT_KEYMAP_IDS = new Set(["ref", "list", "orderedList", "check", "mindmap", "quote", "code", "table"]);
const keymapPath = (id: string): TCommandKeymapPath | undefined => {
if (/^heading[1-6]$/.test(id)) {
diff --git a/app/src/constants.ts b/app/src/constants.ts
index 892903dc57..f9756d1edb 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -655,6 +655,7 @@ export abstract class Constants {
check: {default: "⌘L", custom: "⌘L"},
"ordered-list": {default: "", custom: ""},
list: {default: "", custom: ""},
+ mindmap: {default: "", custom: ""},
table: {default: "⌘O", custom: "⌘O"},
code: {default: "⇧⌘K", custom: "⇧⌘K"},
quote: {default: "", custom: ""},
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index eb623deae3..88654820e8 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -1876,6 +1876,7 @@ export class Gutter {
id: "listMindmap",
icon: "iconMindmap",
label: window.siyuan.languages.mindmap,
+ accelerator: window.siyuan.config.keymap.editor.insert.mindmap?.custom,
click() {
hideElements(["select"], protyle);
void toggleListMindmap(protyle, nodeElement as HTMLElement);
diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.ts
index ce2befe13e..cc7fc0c739 100644
--- a/app/src/protyle/hint/extend.ts
+++ b/app/src/protyle/hint/extend.ts
@@ -200,7 +200,7 @@ export const getBuiltinSlashMenuItems = (protyle: IProtyle): IHintData[] => {
filter: [window.siyuan.languages.mindmap, "mindmap", "思维导图", "siweidaotu", "swdt", "脑图", "naotu", "nt"],
id: "mindmap",
value: `- ${Lute.Caret}\n{: ${Constants.CUSTOM_SY_LIST_MINDMAP}="1"}`,
- html: `<div class="b3-list-item__first"><svg class="b3-list-item__graphic"><use xlink:href="#iconMindmap"></use></svg><span class="b3-list-item__text">${window.siyuan.languages.mindmap}</span></div>`,
+ html: `<div class="b3-list-item__first"><svg class="b3-list-item__graphic"><use xlink:href="#iconMindmap"></use></svg><span class="b3-list-item__text">${window.siyuan.languages.mindmap}</span>${getHotkeyOrMarker(window.siyuan.config.keymap.editor.insert.mindmap?.custom, "")}</div>`,
}, {
filter: [window.siyuan.languages.callout, "callout", "ts", "提示", "tishi", "note"],
id: "calloutNote",
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index b089a36e5e..75b5f460b2 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -1,5 +1,6 @@
import type {BlockQueryRequestInput} from "../../types/api";
import {isProtyleListItemFragment} from "../runtimeCapabilities";
+import {toggleListMindmap} from "../render/listMindmap";
import {hideElements} from "../ui/hideElements";
import {isTabTextBoundary} from "./tabsBoundary";
import {getBlockInsertionContext} from "./blockInsertion";
@@ -2204,6 +2205,33 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return true;
}
}
+ if (matchHotKey(window.siyuan.config.keymap.editor.insert.mindmap, event)) {
+ event.preventDefault();
+ event.stopPropagation();
+ if (isProtyleListItemFragment(protyle) || isInEmbedBlock(nodeElement)) {
+ return;
+ }
+ const selected = Array.from(protyle.wysiwyg.element.querySelectorAll<HTMLElement>(".protyle-wysiwyg--select"));
+ if (selected.length > 1) {
+ return;
+ }
+ const target = selected[0] || nodeElement;
+ const list = getAppendListContext(target, protyle.wysiwyg.element)?.listElement;
+ if (target.dataset.type === "NodeMindmap" || list?.getAttribute(Constants.CUSTOM_SY_LIST_MINDMAP) === "1") {
+ return;
+ }
+ if (list) {
+ hideElements(["select"], protyle);
+ await toggleListMindmap(protyle, list);
+ } else {
+ if (selected.length === 1) {
+ focusBlock(target);
+ hideElements(["select"], protyle);
+ }
+ protyle.hint.fillCommand(`- ${Lute.Caret}\n{: ${Constants.CUSTOM_SY_LIST_MINDMAP}="1"}`, protyle);
+ }
+ return;
+ }
const isMatchList = matchHotKey(window.siyuan.config.keymap.editor.insert.list, event);
const isMatchCheck = matchHotKey(window.siyuan.config.keymap.editor.insert.check, event);
const isMatchOList = matchHotKey(window.siyuan.config.keymap.editor.insert["ordered-list"], event);
diff --git a/app/src/protyle/wysiwyg/mindmapShortcut.test.ts b/app/src/protyle/wysiwyg/mindmapShortcut.test.ts
new file mode 100644
index 0000000000..184cae4292
--- /dev/null
+++ b/app/src/protyle/wysiwyg/mindmapShortcut.test.ts
@@ -0,0 +1,78 @@
+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 {getAppendListContext} from "./listContext";
+
+const source = readFileSync("src/protyle/wysiwyg/keydown.ts", "utf8");
+const start = source.indexOf(" if (matchHotKey(window.siyuan.config.keymap.editor.insert.mindmap");
+const end = source.indexOf(" const isMatchList =", start);
+assert.ok(start >= 0 && end > start);
+const compiled = transpileModule(`(async () => {${source.slice(start, end)}})()`, {
+ compilerOptions: {target: ScriptTarget.ES2021},
+}).outputText;
+
+interface TestBlock {
+ dataset: {type: string};
+ parentElement?: TestBlock;
+ getAttribute: (name: string) => string | null;
+}
+
+const block = (type: string, parentElement?: TestBlock, legacy = false): TestBlock =>
+ ({dataset: {type}, parentElement, getAttribute: (name: string) => name === "data-type" ? type :
+ name === "custom-sy-list-mindmap" && legacy ? "1" : null});
+
+const runShortcut = async (target: TestBlock, options: {
+ selected?: TestBlock[], unbound?: boolean, fragment?: boolean, embedded?: boolean,
+} = {}) => {
+ const converted: unknown[] = [];
+ const inserted: string[] = [];
+ const focused: unknown[] = [];
+ const context = {
+ window: {siyuan: {config: {keymap: {editor: {insert: {mindmap: {custom: options.unbound ? "" : "shortcut"}}}}}}},
+ Constants: {CUSTOM_SY_LIST_MINDMAP: "custom-sy-list-mindmap"},
+ matchHotKey: (binding: {custom: string}) => binding.custom === "shortcut",
+ event: {preventDefault() {}, stopPropagation() {}},
+ protyle: {wysiwyg: {element: {querySelectorAll: () => options.selected || []}},
+ hint: {fillCommand: (value: string) => inserted.push(value)}},
+ nodeElement: target, getAppendListContext,
+ isProtyleListItemFragment: () => options.fragment,
+ isInEmbedBlock: () => options.embedded,
+ toggleListMindmap: async (_protyle: unknown, list: unknown) => converted.push(list),
+ hideElements() {}, focusBlock: (value: unknown) => focused.push(value),
+ Lute: {Caret: "caret"},
+ };
+ await runInNewContext(compiled, context);
+ return {converted, inserted, focused};
+};
+
+test("mindmap shortcut converts the selected list or the list containing the caret", async () => {
+ const list = block("NodeList");
+ const child = block("NodeParagraph", block("NodeListItem", list));
+ assert.deepEqual((await runShortcut(child)).converted, [list]);
+ assert.deepEqual((await runShortcut(block("NodeParagraph"), {selected: [list]})).converted, [list]);
+});
+
+test("mindmap shortcut inserts through the existing command and focuses a selected paragraph", async () => {
+ const paragraph = block("NodeParagraph");
+ for (const selected of [[], [paragraph]]) {
+ const result = await runShortcut(paragraph, {selected});
+ assert.deepEqual(result.inserted, ['- caret\n{: custom-sy-list-mindmap="1"}']);
+ assert.deepEqual(result.focused, selected);
+ assert.deepEqual(result.converted, []);
+ }
+});
+
+test("mindmap shortcut leaves existing maps and unavailable contexts unchanged", async () => {
+ const paragraph = block("NodeParagraph");
+ for (const [target, options] of [
+ [block("NodeMindmap"), {}], [block("NodeList", undefined, true), {}],
+ [paragraph, {unbound: true}], [paragraph, {fragment: true}], [paragraph, {embedded: true}],
+ [paragraph, {selected: [block("NodeList"), block("NodeList")]}],
+ ] as Array<[TestBlock, Parameters<typeof runShortcut>[1]]>) {
+ const result = await runShortcut(target, options);
+ assert.deepEqual(result.converted, []);
+ assert.deepEqual(result.inserted, []);
+ }
+});
diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.ts
index ab51555b44..b93e4afe1e 100644
--- a/app/src/types/config.d.ts
+++ b/app/src/types/config.d.ts
@@ -1351,6 +1351,8 @@ declare namespace Config {
link?: IKey;
mark?: IKey;
memo?: IKey;
+ /** 插入思维导图或将当前列表转换为思维导图,默认未绑定。 */
+ mindmap?: IKey;
ref?: IKey;
strike?: IKey;
sub?: IKey;