This commit is contained in:
Vanessa 2023-05-30 00:35:13 +08:00
parent 30a8a38420
commit 8705132850
2 changed files with 14 additions and 14 deletions

View file

@ -99,23 +99,23 @@ const mergePluginHotkey = (app: App) => {
custom: command.hotkey, custom: command.hotkey,
} }
}; };
return return;
} }
if (!window.siyuan.config.keymap.plugin[plugin.name][command.langKey]) { if (!window.siyuan.config.keymap.plugin[plugin.name][command.langKey]) {
command.customHotkey = command.hotkey; command.customHotkey = command.hotkey;
window.siyuan.config.keymap.plugin[plugin.name][command.langKey] = { window.siyuan.config.keymap.plugin[plugin.name][command.langKey] = {
default: command.hotkey, default: command.hotkey,
custom: command.hotkey, custom: command.hotkey,
} };
return; return;
} }
if (window.siyuan.config.keymap.plugin[plugin.name][command.langKey]) { if (window.siyuan.config.keymap.plugin[plugin.name][command.langKey]) {
command.customHotkey = window.siyuan.config.keymap.plugin[plugin.name][command.langKey].custom || command.hotkey; 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 window.siyuan.config.keymap.plugin[plugin.name][command.langKey]["default"] = command.hotkey;
} }
}) });
}) });
} };
export const onGetConfig = (isStart: boolean, app: App) => { export const onGetConfig = (isStart: boolean, app: App) => {
const matchKeymap1 = matchKeymap(Constants.SIYUAN_KEYMAP.general, "general"); const matchKeymap1 = matchKeymap(Constants.SIYUAN_KEYMAP.general, "general");

View file

@ -33,9 +33,9 @@ export const keymap = {
return html; return html;
}, },
genHTML(app: App) { genHTML(app: App) {
let pluginHtml = '' let pluginHtml = "";
app.plugins.forEach(item => { app.plugins.forEach(item => {
let commandHTML = '' let commandHTML = "";
item.commands.forEach(command => { item.commands.forEach(command => {
const keyValue = updateHotkeyTip(command.customHotkey); const keyValue = updateHotkeyTip(command.customHotkey);
commandHTML += `<label class="b3-list-item b3-list-item--narrow b3-list-item--hide-action"> commandHTML += `<label class="b3-list-item b3-list-item--narrow b3-list-item--hide-action">
@ -61,9 +61,9 @@ export const keymap = {
<div class="fn__none b3-list__panel"> <div class="fn__none b3-list__panel">
${commandHTML} ${commandHTML}
</div> </div>
</div>` </div>`;
} }
}) });
if (pluginHtml) { if (pluginHtml) {
pluginHtml = `<div class="b3-list b3-list--border b3-list--background"> pluginHtml = `<div class="b3-list b3-list--border b3-list--background">
<div class="b3-list-item b3-list-item--narrow toggle"> <div class="b3-list-item b3-list-item--narrow toggle">
@ -73,7 +73,7 @@ export const keymap = {
<span class="b3-list-item__text ft__on-surface">${window.siyuan.languages.plugin}</span> <span class="b3-list-item__text ft__on-surface">${window.siyuan.languages.plugin}</span>
</div> </div>
${pluginHtml} ${pluginHtml}
</div>` </div>`;
} }
return `<label class="fn__flex b3-label config__item"> return `<label class="fn__flex b3-label config__item">
<span class="fn__flex-center">${window.siyuan.languages.keymapTip}</span> <span class="fn__flex-center">${window.siyuan.languages.keymapTip}</span>
@ -243,14 +243,14 @@ export const keymap = {
}, },
_getTip(element: HTMLElement) { _getTip(element: HTMLElement) {
const thirdElement = element.parentElement; const thirdElement = element.parentElement;
let tip = thirdElement.querySelector(".b3-list-item__text").textContent.trim() let tip = thirdElement.querySelector(".b3-list-item__text").textContent.trim();
const secondElement = thirdElement.parentElement.previousElementSibling; const secondElement = thirdElement.parentElement.previousElementSibling;
tip = secondElement.textContent.trim() + "-" + tip; tip = secondElement.textContent.trim() + "-" + tip;
const firstElement = secondElement.parentElement.previousElementSibling; const firstElement = secondElement.parentElement.previousElementSibling;
if (firstElement.classList.contains("b3-list-item")) { if (firstElement.classList.contains("b3-list-item")) {
tip = firstElement.textContent.trim() + "-" + tip; tip = firstElement.textContent.trim() + "-" + tip;
} }
return tip return tip;
}, },
bindEvent() { bindEvent() {
keymap.element.querySelector("#keymapRefreshBtn").addEventListener("click", () => { keymap.element.querySelector("#keymapRefreshBtn").addEventListener("click", () => {
@ -372,7 +372,7 @@ export const keymap = {
showMessage(`${window.siyuan.languages.keymap} [${keymap._getTip(this)}] ${window.siyuan.languages.invalid}`); showMessage(`${window.siyuan.languages.keymap} [${keymap._getTip(this)}] ${window.siyuan.languages.invalid}`);
return; return;
} }
const hasConflict = Array.from(keymap.element.querySelectorAll("label.b3-list-item input")).find(inputItem => { const hasConflict = Array.from(keymap.element.querySelectorAll("label.b3-list-item input")).find((inputItem: HTMLElement) => {
if (!inputItem.isSameNode(this) && inputItem.getAttribute("data-value") === keymapStr) { if (!inputItem.isSameNode(this) && inputItem.getAttribute("data-value") === keymapStr) {
const inputValueList = inputItem.getAttribute("data-key").split(Constants.ZWSP); const inputValueList = inputItem.getAttribute("data-key").split(Constants.ZWSP);
if (inputValueList[1] === "list") { if (inputValueList[1] === "list") {