diff --git a/app/src/config/keymap.ts b/app/src/config/keymap.ts index 4ad2d4fbd..b2f14f904 100644 --- a/app/src/config/keymap.ts +++ b/app/src/config/keymap.ts @@ -54,6 +54,24 @@ export const keymap = { `; }); + item.updateProtyleToolbar([]).forEach(toolbarItem => { + if (typeof toolbarItem === "string" || Constants.INLINE_TYPE.concat("|").includes(toolbarItem.name) || !toolbarItem.hotkey) { + return + } + const dockKeymap = window.siyuan.config.keymap.plugin[item.name][toolbarItem.name]; + const keyValue = updateHotkeyTip(dockKeymap.custom); + commandHTML += ``; + }) Object.keys(item.docks).forEach(key => { const dockConfig = item.docks[key].config; if (!dockConfig.hotkey) { diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.ts index 42af4c850..54214d5f8 100644 --- a/app/src/plugin/index.ts +++ b/app/src/plugin/index.ts @@ -15,6 +15,7 @@ import {hasClosestByAttribute} from "../protyle/util/hasClosest"; import {BlockPanel} from "../block/Panel"; import {Setting} from "./Setting"; import {clearOBG} from "../layout/dock/util"; +import {Constants} from "../constants"; export class Plugin { private app: App; @@ -75,6 +76,29 @@ export class Plugin { value: options.name, writable: false, }); + + this.updateProtyleToolbar([]).forEach(toolbarItem => { + if (typeof toolbarItem === "string" || Constants.INLINE_TYPE.concat("|").includes(toolbarItem.name) || !toolbarItem.hotkey) { + return + } + if (!window.siyuan.config.keymap.plugin) { + window.siyuan.config.keymap.plugin = {}; + } + if (!window.siyuan.config.keymap.plugin[options.name]) { + window.siyuan.config.keymap.plugin[options.name] = { + [toolbarItem.name]: { + default: toolbarItem.hotkey, + custom: toolbarItem.hotkey, + } + }; + } + if (!window.siyuan.config.keymap.plugin[options.name][toolbarItem.name]) { + window.siyuan.config.keymap.plugin[options.name][toolbarItem.name] = { + default: toolbarItem.hotkey, + custom: toolbarItem.hotkey, + } + } + }) } public onload() { diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index e36357658..44d7df389 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -69,7 +69,14 @@ export class Toolbar { /// #endif this.toolbarHeight = 29; protyle.app.plugins.forEach(item => { - options.toolbar = toolbarKeyToMenu(item.updateProtyleToolbar(options.toolbar)); + const pluginToolbar = item.updateProtyleToolbar(options.toolbar) + pluginToolbar.forEach(toolbarItem => { + if (typeof toolbarItem === "string" || Constants.INLINE_TYPE.concat("|").includes(toolbarItem.name) || !toolbarItem.hotkey) { + return + } + toolbarItem.hotkey = window.siyuan.config.keymap.plugin[item.name][toolbarItem.name].custom; + }) + options.toolbar = toolbarKeyToMenu(pluginToolbar); }); options.toolbar.forEach((menuItem: IMenuItem) => { const itemElement = this.genItem(protyle, menuItem); @@ -81,7 +88,14 @@ export class Toolbar { this.element.innerHTML = ""; protyle.options.toolbar = toolbarKeyToMenu(Constants.PROTYLE_TOOLBAR); protyle.app.plugins.forEach(item => { - protyle.options.toolbar = toolbarKeyToMenu(item.updateProtyleToolbar(protyle.options.toolbar)); + const pluginToolbar = item.updateProtyleToolbar(protyle.options.toolbar) + pluginToolbar.forEach(toolbarItem => { + if (typeof toolbarItem === "string" || Constants.INLINE_TYPE.concat("|").includes(toolbarItem.name) || !toolbarItem.hotkey) { + return + } + toolbarItem.hotkey = window.siyuan.config.keymap.plugin[item.name][toolbarItem.name].custom; + }) + protyle.options.toolbar = toolbarKeyToMenu(pluginToolbar); }); protyle.options.toolbar.forEach((menuItem: IMenuItem) => { const itemElement = this.genItem(protyle, menuItem);