Skip to content

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

:sparkles: Show insert shortcuts in the command panel https://github.com/siyuan-note/siyuan/issues/19811

Danielb19d7fa1ed3c
diff --git a/app/src/boot/globalEvent/command/panel.ts b/app/src/boot/globalEvent/command/panel.ts
index 5743abcbbe..90d8baf40b 100644
--- a/app/src/boot/globalEvent/command/panel.ts
+++ b/app/src/boot/globalEvent/command/panel.ts
@@ -29,12 +29,16 @@ const renderCommands = (listElement: HTMLElement, commands: ICommandDefinition[]
const textElement = document.createElement("span");
textElement.className = "b3-list-item__text";
textElement.textContent = command.label();
- const hotkeyElement = document.createElement("span");
- hotkeyElement.className = `b3-list-item__meta${isMobile() ? " fn__none" : ""}`;
- hotkeyElement.textContent = command.keymapPath ?
+ const hotkey = command.keymapPath ?
getKeymapBindings(getKeymapItem(window.siyuan.config.keymap, command.keymapPath)).map(key => updateHotkeyTip(key)).join(" / ") :
updateHotkeyTip(command.hotkey?.() || "");
- itemElement.append(textElement, hotkeyElement);
+ itemElement.append(textElement);
+ if (hotkey) {
+ const hotkeyElement = document.createElement("span");
+ hotkeyElement.className = "b3-list-item__meta";
+ hotkeyElement.textContent = hotkey;
+ itemElement.append(hotkeyElement);
+ }
fragment.append(itemElement);
});
listElement.replaceChildren(fragment);
diff --git a/app/src/command/insertCommands.test.ts b/app/src/command/insertCommands.test.ts
index 00950f3020..1eac91db57 100644
--- a/app/src/command/insertCommands.test.ts
+++ b/app/src/command/insertCommands.test.ts
@@ -64,6 +64,11 @@ test("insert commands search and execute existing insertion actions at the saved
assert.ok(visible.includes("core.mobile.insert.insertAsset"));
assert.ok(visible.includes("core.mobile.insert.mindmap"));
assert.ok(!visible.includes("core.mobile.insert.insertPhoto"));
+ 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.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");
const recent = recordPaletteCommand([], "core.mobile.insert.assets");
assert.equal(queryCommandPalette(registry, context, "", recent)[0].id, "core.mobile.insert.assets");
@@ -90,6 +95,8 @@ test("insert commands search and execute existing insertion actions at the saved
assert.ok(desktopVisible.includes("core.insert.template"));
assert.ok(desktopVisible.includes("core.insert.mindmap"));
assert.ok(!desktopVisible.includes("core.insert.insertPhoto"));
+ assert.ok(desktopRegistry.list({...desktopContext, environment: "desktop-window"}).some(command => command.id === "core.insert.template"));
+ assert.ok(desktopRegistry.list({...desktopContext, environment: "browser-desktop"}).some(command => command.id === "core.insert.template"));
assert.equal(queryCommandPalette(desktopRegistry, desktopContext, "模板")[0].id, "core.insert.template");
assert.equal((await desktopRegistry.execute("core.insert.template", desktopContext)).status, "executed");
assert.deepEqual(fills, ["template-value", "((", "template-value"]);
diff --git a/app/src/command/insertCommands.ts b/app/src/command/insertCommands.ts
index 154f697f21..1849c36a9a 100644
--- a/app/src/command/insertCommands.ts
+++ b/app/src/command/insertCommands.ts
@@ -1,6 +1,6 @@
import {getCommandRegistry} from "./service";
import {getEnglishCommandLabel} from "./english";
-import type {ICommandContextSnapshot, ICommandDefinition} from "./types";
+import type {ICommandContextSnapshot, ICommandDefinition, TCommandKeymapPath} from "./types";
import {getBuiltinSlashMenuItems} from "../protyle/hint/extend";
import {isBuiltinInlineStyleVisible, type TBuiltinInlineStyleID} from "../protyle/toolbar/inlineStyle";
import {focusByRange} from "../protyle/util/selection";
@@ -28,6 +28,19 @@ 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 keymapPath = (id: string): TCommandKeymapPath | undefined => {
+ if (/^heading[1-6]$/.test(id)) {
+ return ["editor", "heading", id];
+ }
+ if (id === "aiWriting") {
+ return ["editor", "general", id];
+ }
+ if (INSERT_KEYMAP_IDS.has(id)) {
+ return ["editor", "insert", id === "orderedList" ? "ordered-list" : id];
+ }
+};
const labelKey = (id: string) => id === "orderedList" ? "ordered-list" : id;
const label = (id: string, english = false) => {
@@ -134,6 +147,7 @@ export const ensureInsertCommands = (app: object, mobile: boolean) => {
label: () => label(id),
englishLabel: () => label(id, true),
keywords: () => [id],
+ keymapPath: keymapPath(id),
surfaces: ["commandPanel"],
platform: environment => mobile ? environment === "mobile" || environment === "browser-mobile" :
environment === "desktop" || environment === "desktop-window" || environment === "browser-desktop",