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

@ -802,10 +802,29 @@ export const globalShortcut = (app: App) => {
}
// 面板的操作
if (!isTabWindow && panelTreeKeydown(event)) {
if (!isTabWindow && panelTreeKeydown(app, event)) {
return;
}
let matchCommand = false;
app.plugins.find(item => {
item.commands.find(command => {
if (command.callback &&
!command.fileTreeCallback && !command.editorCallback&& !command.dockCallback
&& matchHotKey(command.customHotkey, event)) {
matchCommand = true;
command.callback();
return true;
}
});
if (matchCommand) {
return true;
}
});
if (matchCommand) {
return true;
}
let searchKey = "";
if (matchHotKey(window.siyuan.config.keymap.general.replace.custom, event)) {
searchKey = window.siyuan.config.keymap.general.replace.custom;
@ -1112,6 +1131,24 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
return false;
}
const files = dockFile.data.file as Files;
let matchCommand = false;
app.plugins.find(item => {
item.commands.find(command => {
if (command.fileTreeCallback && matchHotKey(command.customHotkey, event)) {
matchCommand = true;
command.fileTreeCallback(files);
return true;
}
});
if (matchCommand) {
return true;
}
});
if (matchCommand) {
return true;
}
if (matchHotKey(window.siyuan.config.keymap.general.selectOpen1.custom, event)) {
event.preventDefault();
const element = document.querySelector(".layout__wnd--active > .fn__flex > .layout-tab-bar > .item--focus") ||
@ -1402,7 +1439,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
}
};
const panelTreeKeydown = (event: KeyboardEvent) => {
const panelTreeKeydown = (app: App, event: KeyboardEvent) => {
// 面板折叠展开操作
const target = event.target as HTMLElement;
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" ||
@ -1451,6 +1488,23 @@ const panelTreeKeydown = (event: KeyboardEvent) => {
activePanelElement.classList.contains("sy__graph")) {
return false;
}
let matchCommand = false;
app.plugins.find(item => {
item.commands.find(command => {
if (command.dockCallback && matchHotKey(command.customHotkey, event)) {
matchCommand = true;
command.dockCallback(activePanelElement as HTMLElement);
return true;
}
});
if (matchCommand) {
return true;
}
});
if (matchCommand) {
return true;
}
const model = (getInstanceById(activePanelElement.getAttribute("data-id"), window.siyuan.layout.layout) as Tab)?.model;
if (!model) {
return false;

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)) {