Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Fix F10 shortcut key input (#17905)

Jeffrey Chenb3a54e1f7da7
diff --git a/app/src/protyle/util/hotKey.ts b/app/src/protyle/util/hotKey.ts
index 1225511df0..e364be1db8 100644
--- a/app/src/protyle/util/hotKey.ts
+++ b/app/src/protyle/util/hotKey.ts
@@ -42,16 +42,6 @@ export const matchAuxiliaryHotKey = (hotKey: string, event: KeyboardEvent) => {
return true;
};
-const replaceDirect = (hotKey: string, keyCode: string) => {
- const hotKeys = hotKey.replace(keyCode, Constants.ZWSP).split("");
- hotKeys.forEach((item, index) => {
- if (item === Constants.ZWSP) {
- hotKeys[index] = keyCode;
- }
- });
- return hotKeys;
-};
-
export const matchHotKey = (hotKey: string, event: KeyboardEvent) => {
if (!hotKey) {
return false;
@@ -77,25 +67,16 @@ export const matchHotKey = (hotKey: string, event: KeyboardEvent) => {
return false;
}
- let hotKeys = hotKey.split("");
- if (hotKey.indexOf("F") > -1) {
- hotKeys.forEach((item, index) => {
- if (item === "F") {
- // F1-F12
- hotKeys[index] = "F" + hotKeys.splice(index + 1, 1);
- if (hotKeys[index + 1]) {
- hotKeys[index + 1] += hotKeys.splice(index + 1, 1);
- }
- }
- });
- } else if (hotKey.indexOf("PageUp") > -1) {
- hotKeys = replaceDirect(hotKey, "PageUp");
- } else if (hotKey.indexOf("PageDown") > -1) {
- hotKeys = replaceDirect(hotKey, "PageDown");
- } else if (hotKey.indexOf("Home") > -1) {
- hotKeys = replaceDirect(hotKey, "Home");
- } else if (hotKey.indexOf("End") > -1) {
- hotKeys = replaceDirect(hotKey, "End");
+ // 将快捷键字符串拆分为 多个修饰键 + 一个主键,例如 ⌥⇧F10 → ["⌥", "⇧", "F10"]
+ const hotKeys: string[] = [];
+ let hotKeyIndex = 0;
+ while (hotKeyIndex < hotKey.length && "⌃⌥⇧⌘".includes(hotKey[hotKeyIndex])) {
+ hotKeys.push(hotKey[hotKeyIndex]);
+ hotKeyIndex++;
+ }
+ const mainKey = hotKey.slice(hotKeyIndex);
+ if (mainKey) {
+ hotKeys.push(mainKey);
}
// 是否匹配 ⇧[]