This commit is contained in:
Vanessa 2023-10-22 17:23:22 +08:00
parent 654c2a47a7
commit 1922f6fa9d
2 changed files with 28 additions and 3 deletions

View file

@ -743,6 +743,9 @@ app.whenReady().then(() => {
case "openDevTools": case "openDevTools":
event.sender.openDevTools({mode: "bottom"}); event.sender.openDevTools({mode: "bottom"});
break; break;
case "unregisterAll":
globalShortcut.unregisterAll();
break;
case "show": case "show":
showWindow(currentWindow); showWindow(currentWindow);
break; break;

View file

@ -1,10 +1,13 @@
import {isCtrl, isMac, updateHotkeyTip} from "../protyle/util/compatibility"; import {isCtrl, isMac, updateHotkeyTip} from "../protyle/util/compatibility";
import {Constants} from "../constants"; import {Constants} from "../constants";
import {showMessage} from "../dialog/message"; import {hideMessage, showMessage} from "../dialog/message";
import {fetchPost} from "../util/fetch"; import {fetchPost} from "../util/fetch";
import {exportLayout} from "../layout/util"; import {exportLayout} from "../layout/util";
import {confirmDialog} from "../dialog/confirmDialog"; import {confirmDialog} from "../dialog/confirmDialog";
import {App} from "../index"; import {App} from "../index";
/// #if !BROWSER
import {ipcRenderer} from "electron";
/// #endif
import {sendGlobalShortcut} from "../boot/globalEvent/keydown"; import {sendGlobalShortcut} from "../boot/globalEvent/keydown";
export const keymap = { export const keymap = {
@ -272,6 +275,16 @@ export const keymap = {
} }
keymap.search(searchElement.value, searchKeymapElement.value); keymap.search(searchElement.value, searchKeymapElement.value);
}); });
/// #if !BROWSER
searchKeymapElement.addEventListener("focus", () => {
ipcRenderer.send(Constants.SIYUAN_CMD, {
cmd: "unregisterAll",
});
});
/// #endif
searchKeymapElement.addEventListener("blur", () => {
sendGlobalShortcut(app);
});
searchKeymapElement.addEventListener("keydown", function (event: KeyboardEvent) { searchKeymapElement.addEventListener("keydown", function (event: KeyboardEvent) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
@ -373,7 +386,7 @@ export const keymap = {
showMessage(`${window.siyuan.languages.invalid} [${adoptKeymapStr}]`); showMessage(`${window.siyuan.languages.invalid} [${adoptKeymapStr}]`);
hasConflict = true; hasConflict = true;
} }
Array.from(keymap.element.querySelectorAll("label.b3-list-item input")).find((inputItem: HTMLElement) => { 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") {
@ -391,18 +404,27 @@ export const keymap = {
this.value = updateHotkeyTip(this.getAttribute("data-value")); this.value = updateHotkeyTip(this.getAttribute("data-value"));
return; return;
} }
hideMessage();
this.setAttribute("data-value", keymapStr); this.setAttribute("data-value", keymapStr);
this.value = adoptKeymapStr; this.value = adoptKeymapStr;
keymap._setkeymap(app); keymap._setkeymap(app);
}, 1000); }, Constants.TIMEOUT_TRANSITION);
}); });
item.addEventListener("blur", function () { item.addEventListener("blur", function () {
sendGlobalShortcut(app);
setTimeout(() => { setTimeout(() => {
this.classList.add("fn__none"); this.classList.add("fn__none");
this.previousElementSibling.textContent = this.value; this.previousElementSibling.textContent = this.value;
this.previousElementSibling.classList.remove("fn__none"); this.previousElementSibling.classList.remove("fn__none");
}, Constants.TIMEOUT_INPUT); // 隐藏的话点击删除无法 target 会为 li }, Constants.TIMEOUT_INPUT); // 隐藏的话点击删除无法 target 会为 li
}); });
/// #if !BROWSER
item.addEventListener("focus", () => {
ipcRenderer.send(Constants.SIYUAN_CMD, {
cmd: "unregisterAll",
});
});
/// #endif
}); });
}, },
_getKeymapString(event: KeyboardEvent) { _getKeymapString(event: KeyboardEvent) {