An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:recycle: Use keymap as the only dock shortcut source https://github.com/siyuan-note/siyuan/issues/18765
Daniel8d84b490fd6f
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.tsindex d27e8c84aa..1668ddb887 100644--- a/app/src/boot/globalEvent/keydown.ts+++ b/app/src/boot/globalEvent/keydown.ts@@ -30,6 +30,7 @@ import {goBack, goForward} from "../../util/backForward";import {getDisplayName, getNotebookName, isEncryptedBox} from "../../util/pathName";import {openFileById} from "../../editor/util";import {getAllDocks, getAllModels, getAllTabs} from "../../layout/getAll";+import {getDockHotkey} from "../../layout/dock/hotkey";import {focusBlock, focusByRange, getBlockElementsByRange} from "../../protyle/util/selection";import {initFileMenu, initNavigationMenu} from "../../menus/navigation";import {bindMenuKeydown} from "../../menus/Menu";@@ -1320,7 +1321,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {dockHtml += `<li data-type="${item.type}" data-index="${index + 1}" class="b3-list-item"><svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg><span class="b3-list-item__text">${item.title}</span>- <span class="b3-list-item__meta">${updateHotkeyTip(item.hotkey || "")}</span>+ <span class="b3-list-item__meta">${updateHotkeyTip(getDockHotkey(item))}</span></li>`;});dockHtml = dockHtml + "</ul>";@@ -1481,7 +1482,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {return;}const matchDock = getAllDocks().find(item => {- if (matchHotKey(item.hotkey, event)) {+ if (matchHotKey(getDockHotkey(item), event)) {getDockByType(item.type).toggleModel(item.type);event.preventDefault();return true;diff --git a/app/src/business/openRecentDocs.ts b/app/src/business/openRecentDocs.tsindex ff9202953b..4f57a77caa 100644--- a/app/src/business/openRecentDocs.ts+++ b/app/src/business/openRecentDocs.ts@@ -5,6 +5,7 @@ import {escapeHtml} from "../util/escape";import {isWindow} from "../util/functions";import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";import {getAllDocks} from "../layout/getAll";+import {getDockHotkey} from "../layout/dock/hotkey";import {Dialog} from "../dialog";import {focusByRange} from "../protyle/util/selection";import {hasClosestByClassName} from "../protyle/util/hasClosest";@@ -57,7 +58,7 @@ const renderRecentDocsContent = async (data: {dockHtml += `<li data-type="${item.type}" data-index="${docIndex}" class="b3-list-item${!switchPath ? " b3-list-item--focus" : ""}"><svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg><span class="b3-list-item__text">${item.title}</span>- <span class="b3-list-item__meta">${updateHotkeyTip(item.hotkey)}</span>+ <span class="b3-list-item__meta">${updateHotkeyTip(getDockHotkey(item))}</span></li>`;if (!switchPath) {switchPath = item.title;diff --git a/app/src/layout/dock/hotkey.test.ts b/app/src/layout/dock/hotkey.test.tsindex 038ffec03e..e1913e5b92 100644--- a/app/src/layout/dock/hotkey.test.ts+++ b/app/src/layout/dock/hotkey.test.ts@@ -1,22 +1,33 @@import * as assert from "node:assert/strict";import test from "node:test";-import {updateDockHotkeyData} from "./hotkey";+import {getDockHotkey} from "./hotkey";test("dock hotkeys use the latest keymap configuration", () => {- const docks = [{+ const internalDock = {type: "agentChat",hotkeyLangId: "agentChat",- hotkey: "",- }, {+ } as Config.IUILayoutDockTab;+ const pluginDock = {type: "pluginDock",- hotkey: "⌘P",- }] as Config.IUILayoutDockTab[];+ } as Config.IUILayoutDockTab;const keymap = {- agentChat: {default: "", custom: "⌘J"},- } as Config.IKeymapGeneral;+ general: {+ agentChat: {default: "", custom: "⌘J"},+ },+ plugin: {+ plugin: {+ pluginDock: {default: "⌘P", custom: "⌘K"},+ },+ },+ };+ const plugins = [{+ name: "plugin",+ docks: {pluginDock: {}},+ }];- updateDockHotkeyData(docks, keymap);-- assert.equal(docks[0].hotkey, "⌘J");- assert.equal(docks[1].hotkey, "⌘P");+ assert.equal(getDockHotkey(internalDock, keymap, plugins), "⌘J");+ assert.equal(getDockHotkey(pluginDock, keymap, plugins), "⌘K");+ keymap.plugin.plugin.pluginDock.custom = "";+ assert.equal(getDockHotkey(pluginDock, keymap, plugins), "");+ assert.equal(getDockHotkey({...pluginDock, type: "unknown"}, keymap, plugins), "");});diff --git a/app/src/layout/dock/hotkey.ts b/app/src/layout/dock/hotkey.tsindex ab74f23e26..f1adfc2efc 100644--- a/app/src/layout/dock/hotkey.ts+++ b/app/src/layout/dock/hotkey.ts@@ -1,11 +1,24 @@-export const updateDockHotkeyData = (- docks: Config.IUILayoutDockTab[],- keymap: Config.IKeymapGeneral,+interface IPluginDockOwner {+ name: string;+ docks: Record<string, unknown>;+}++interface IDockKeymap {+ general: Config.IKeys;+ plugin?: Config.IKeymapPlugin;+}++export const getDockHotkey = (+ dock: Config.IUILayoutDockTab,+ keymap: IDockKeymap = window.siyuan.config.keymap,+ plugins: IPluginDockOwner[] = window.siyuan.ws.app.plugins,) => {- docks.forEach((item) => {- if (!item.hotkeyLangId) {- return;- }- item.hotkey = keymap[item.hotkeyLangId]?.custom || "";- });+ if (dock.hotkeyLangId) {+ return keymap.general[dock.hotkeyLangId]?.custom || "";+ }+ const plugin = plugins.find((item) => Object.prototype.hasOwnProperty.call(item.docks, dock.type));+ if (!plugin) {+ return "";+ }+ return keymap.plugin?.[plugin.name]?.[dock.type]?.custom || "";};diff --git a/app/src/layout/dock/index.ts b/app/src/layout/dock/index.tsindex 9316912969..715b7ae651 100644--- a/app/src/layout/dock/index.ts+++ b/app/src/layout/dock/index.ts@@ -27,6 +27,7 @@ import {updatePluginDockPlacements,updatePluginDockShowStates,} from "./pluginDockState";+import {getDockHotkey} from "./hotkey";const TYPES = ["file", "outline", "inbox", "bookmark", "tag", "graph", "globalGraph", "backlink", "agentChat"];@@ -931,7 +932,8 @@ export class Dock {} else if (item.type === "tags") {item.icon = "iconTag";}- html += `<span data-height="${item.size.height}" data-width="${item.size.width}" data-type="${item.type}" data-index="${index}" data-hotkey="${item.hotkey || ""}" data-hotkeylangid="${item.hotkeyLangId || ""}" data-title="${item.title}" data-position="${tooltipPosition}" class="dock__item${item.show ? " dock__item--active" : ""} ariaLabel" aria-label="<span style='white-space:pre'>${item.title} ${item.hotkey ? updateHotkeyTip(item.hotkey) : ""}${window.siyuan.languages.dockTip}</span>">+ const hotkey = getDockHotkey(item);+ html += `<span data-height="${item.size.height}" data-width="${item.size.width}" data-type="${item.type}" data-index="${index}" data-hotkeylangid="${item.hotkeyLangId || ""}" data-title="${item.title}" data-position="${tooltipPosition}" class="dock__item${item.show ? " dock__item--active" : ""} ariaLabel" aria-label="<span style='white-space:pre'>${item.title} ${hotkey ? updateHotkeyTip(hotkey) : ""}${window.siyuan.languages.dockTip}</span>"><svg><use xlink:href="#${item.icon}"></use></svg></span>`;this.data[item.type] = true;diff --git a/app/src/layout/dock/util.ts b/app/src/layout/dock/util.tsindex 60868e0553..f08b1c4322 100644--- a/app/src/layout/dock/util.ts+++ b/app/src/layout/dock/util.ts@@ -14,7 +14,7 @@ import {Constants} from "../../constants";import {getDocDisplayName, isEncryptedBox} from "../../util/pathName";import {showMessage} from "../../dialog/message";import {updateHotkeyTip} from "../../protyle/util/compatibility";-import {updateDockHotkeyData} from "./hotkey";+import {getDockHotkey} from "./hotkey";export const openBacklink = async (options: {app: App,@@ -207,15 +207,11 @@ export const resetFloatDockSize = () => {export const updateDockHotkeys = () => {const docks = getAllDocks();- updateDockHotkeyData(docks, window.siyuan.config.keymap.general);docks.forEach((item) => {- if (!item.hotkeyLangId) {- return;- }+ const hotkey = getDockHotkey(item);document.querySelectorAll<HTMLElement>(`.dock__item[data-type="${CSS.escape(item.type)}"]`).forEach((element) => {- element.dataset.hotkey = item.hotkey;- element.setAttribute("aria-label", `<span style='white-space:pre'>${item.title} ${- item.hotkey ? updateHotkeyTip(item.hotkey) : ""+ element.setAttribute("aria-label", `<span style='white-space:pre'>${element.dataset.title || ""} ${+ hotkey ? updateHotkeyTip(hotkey) : ""}${window.siyuan.languages.dockTip}</span>`);});});diff --git a/app/src/layout/util.ts b/app/src/layout/util.tsindex bd6c554a72..13b99c2137 100644--- a/app/src/layout/util.ts+++ b/app/src/layout/util.ts@@ -117,7 +117,6 @@ const dockToJSON = (dock: Dock) => {title: item.getAttribute("data-title"),show: item.classList.contains("dock__item--active"),icon: item.querySelector("use").getAttribute("xlink:href").substring(1),- hotkey: item.getAttribute("data-hotkey") || "",hotkeyLangId: item.getAttribute("data-hotkeylangid") || ""});});@@ -313,8 +312,6 @@ const initInternalDock = (dockItem: Config.IUILayoutDockTab[]) => {}if (existSubItem.hotkeyLangId) {existSubItem.title = window.siyuan.languages[existSubItem.hotkeyLangId];- const km = window.siyuan.config.keymap.general[existSubItem.hotkeyLangId];- existSubItem.hotkey = km ? km.custom : "";}});};diff --git a/app/src/menus/workspace.ts b/app/src/menus/workspace.tsindex f4cf175b4f..fc7cbcf817 100644--- a/app/src/menus/workspace.ts+++ b/app/src/menus/workspace.ts@@ -11,6 +11,7 @@ import {isInAndroid, isInHarmony, isInMobileApp, isIPad, setStorageVal, writeTeximport {openCard} from "../card/openCard";import {openSetting} from "../config";import {getAllDocks} from "../layout/getAll";+import {getDockHotkey} from "../layout/dock/hotkey";import {exportLayout, getAllLayout} from "../layout/util";import {getDockByType} from "../layout/tabUtil";import {exitSiYuan, lockScreen} from "../dialog/processSystem";@@ -163,7 +164,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {dockMenu.push({id: item.type,icon: item.icon,- accelerator: item.hotkey,+ accelerator: getDockHotkey(item),label: item.title,click() {getDockByType(item.type).toggleModel(item.type);diff --git a/app/src/plugin/loader.ts b/app/src/plugin/loader.tsindex 373cf8a977..c5fcd91b45 100644--- a/app/src/plugin/loader.ts+++ b/app/src/plugin/loader.ts@@ -228,7 +228,6 @@ export const addPluginDock = (plugin: Plugin) => {plugin.docks[key].config = window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key];}const dock = plugin.docks[key];- const hotkey = window.siyuan.config.keymap.plugin[plugin.name] ? window.siyuan.config.keymap.plugin[plugin.name][key]?.custom : undefined;if (dock.config.position.startsWith("Left")) {window.siyuan.layout.leftDock.genButton([{type: key,@@ -236,7 +235,6 @@ export const addPluginDock = (plugin: Plugin) => {show: dock.config.show,icon: dock.config.icon,title: dock.config.title,- hotkey}], dock.config.position === "LeftBottom" ? 1 : 0, dock.config.index);} else if (dock.config.position.startsWith("Bottom")) {window.siyuan.layout.bottomDock.genButton([{@@ -245,7 +243,6 @@ export const addPluginDock = (plugin: Plugin) => {show: dock.config.show,icon: dock.config.icon,title: dock.config.title,- hotkey}], dock.config.position === "BottomRight" ? 1 : 0, dock.config.index);} else if (dock.config.position.startsWith("Right")) {window.siyuan.layout.rightDock.genButton([{@@ -254,7 +251,6 @@ export const addPluginDock = (plugin: Plugin) => {show: dock.config.show,icon: dock.config.icon,title: dock.config.title,- hotkey}], dock.config.position === "RightBottom" ? 1 : 0, dock.config.index);}});diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.tsindex 7fb1ded999..9f7e8f9fd9 100644--- a/app/src/types/config.d.ts+++ b/app/src/types/config.d.ts@@ -2099,10 +2099,6 @@ declare namespace Config {* SiYuan dock tab data*/export interface IUILayoutDockTab {- /**- * Dock tab hotkey- */- hotkey?: string;/*** Hotkey description ID*/