This commit is contained in:
Vanessa 2023-05-30 00:27:47 +08:00
parent 52c9b5fbca
commit 4b02a8a846
11 changed files with 197 additions and 22 deletions

View file

@ -85,6 +85,38 @@ const hasKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "edito
return match;
};
const mergePluginHotkey = (app: App) => {
if (!window.siyuan.config.keymap.plugin) {
window.siyuan.config.keymap.plugin = {};
}
app.plugins.forEach(plugin => {
plugin.commands.forEach(command => {
if (!window.siyuan.config.keymap.plugin[plugin.name]) {
command.customHotkey = command.hotkey;
window.siyuan.config.keymap.plugin[plugin.name] = {
[command.langKey]: {
default: command.hotkey,
custom: command.hotkey,
}
};
return
}
if (!window.siyuan.config.keymap.plugin[plugin.name][command.langKey]) {
command.customHotkey = command.hotkey;
window.siyuan.config.keymap.plugin[plugin.name][command.langKey] = {
default: command.hotkey,
custom: command.hotkey,
}
return;
}
if (window.siyuan.config.keymap.plugin[plugin.name][command.langKey]) {
command.customHotkey = window.siyuan.config.keymap.plugin[plugin.name][command.langKey].custom || command.hotkey;
window.siyuan.config.keymap.plugin[plugin.name][command.langKey]["default"] = command.hotkey
}
})
})
}
export const onGetConfig = (isStart: boolean, app: App) => {
const matchKeymap1 = matchKeymap(Constants.SIYUAN_KEYMAP.general, "general");
const matchKeymap2 = matchKeymap(Constants.SIYUAN_KEYMAP.editor.general, "editor", "general");
@ -99,6 +131,7 @@ export const onGetConfig = (isStart: boolean, app: App) => {
const hasKeymap4 = hasKeymap(Constants.SIYUAN_KEYMAP.editor.heading, "editor", "heading");
const hasKeymap5 = hasKeymap(Constants.SIYUAN_KEYMAP.editor.list, "editor", "list");
const hasKeymap6 = hasKeymap(Constants.SIYUAN_KEYMAP.editor.table, "editor", "table");
mergePluginHotkey(app);
if (!window.siyuan.config.readonly &&
(!matchKeymap1 || !matchKeymap2 || !matchKeymap3 || !matchKeymap4 || !matchKeymap5 || !matchKeymap6 ||
!hasKeymap1 || !hasKeymap2 || !hasKeymap3 || !hasKeymap4 || !hasKeymap5 || !hasKeymap6)) {