Vanessa 2024-03-19 23:14:18 +08:00
parent 71a7a71b3a
commit 511a793c7b
2 changed files with 41 additions and 3 deletions

View file

@ -48,6 +48,22 @@ export const keymap = {
</span>
<span data-type="update" class="config-keymap__key">${keyValue}</span>
<input data-key="plugin${Constants.ZWSP}${item.name}${Constants.ZWSP}${command.langKey}" data-value="${command.customHotkey}" data-default="${command.hotkey}" class="b3-text-field fn__none" value="${keyValue}" spellcheck="false">
</label>`;
});
Object.keys(item.docks).forEach(key => {
const dockConfig = item.docks[key].config;
const dockKeymap = window.siyuan.config.keymap.plugin[item.name][key];
const keyValue = updateHotkeyTip(dockKeymap.custom);
commandHTML += `<label class="b3-list-item b3-list-item--narrow b3-list-item--hide-action">
<span class="b3-list-item__text">${dockConfig.title}</span>
<span data-type="reset" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.reset}">
<svg><use xlink:href="#iconUndo"></use></svg>
</span>
<span data-type="clear" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.remove}">
<svg><use xlink:href="#iconTrashcan"></use></svg>
</span>
<span data-type="update" class="config-keymap__key">${keyValue}</span>
<input data-key="plugin${Constants.ZWSP}${item.name}${Constants.ZWSP}${key}" data-value="${dockKeymap.custom}" data-default="${dockKeymap.default}" class="b3-text-field fn__none" value="${keyValue}" spellcheck="false">
</label>`;
});
if (commandHTML) {

View file

@ -138,6 +138,27 @@ const mergePluginHotkey = (plugin: Plugin) => {
i--;
}
}
Object.keys(plugin.docks).forEach(dockKey => {
const dock = plugin.docks[dockKey];
if (!window.siyuan.config.keymap.plugin[plugin.name]) {
window.siyuan.config.keymap.plugin[plugin.name] = {
[dockKey]: {
default: dock.config.hotkey,
custom: dock.config.hotkey,
}
};
} else if (!window.siyuan.config.keymap.plugin[plugin.name][dockKey]) {
window.siyuan.config.keymap.plugin[plugin.name][dockKey] = {
default: dock.config.hotkey,
custom: dock.config.hotkey,
};
} else if (window.siyuan.config.keymap.plugin[plugin.name][dockKey]) {
if (typeof window.siyuan.config.keymap.plugin[plugin.name][dockKey].custom !== "string") {
window.siyuan.config.keymap.plugin[plugin.name][dockKey].custom = dock.config.hotkey;
}
window.siyuan.config.keymap.plugin[plugin.name][dockKey]["default"] = dock.config.hotkey;
}
})
};
export const afterLoadPlugin = (plugin: Plugin) => {
@ -201,6 +222,7 @@ export const afterLoadPlugin = (plugin: Plugin) => {
});
Object.keys(plugin.docks).forEach(key => {
const dock = plugin.docks[key];
const hotkey = window.siyuan.config.keymap.plugin[plugin.name][key].custom
if (dock.config.position.startsWith("Left")) {
window.siyuan.layout.leftDock.genButton([{
type: key,
@ -208,7 +230,7 @@ export const afterLoadPlugin = (plugin: Plugin) => {
show: dock.config.show,
icon: dock.config.icon,
title: dock.config.title,
hotkey: dock.config.hotkey
hotkey
}], dock.config.position === "LeftBottom" ? 1 : 0, dock.config.index);
} else if (dock.config.position.startsWith("Bottom")) {
window.siyuan.layout.bottomDock.genButton([{
@ -217,7 +239,7 @@ export const afterLoadPlugin = (plugin: Plugin) => {
show: dock.config.show,
icon: dock.config.icon,
title: dock.config.title,
hotkey: dock.config.hotkey
hotkey
}], dock.config.position === "BottomRight" ? 1 : 0, dock.config.index);
} else if (dock.config.position.startsWith("Right")) {
window.siyuan.layout.rightDock.genButton([{
@ -226,7 +248,7 @@ export const afterLoadPlugin = (plugin: Plugin) => {
show: dock.config.show,
icon: dock.config.icon,
title: dock.config.title,
hotkey: dock.config.hotkey
hotkey
}], dock.config.position === "RightBottom" ? 1 : 0, dock.config.index);
}
});