Skip to content

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

:recycle: Refactor updateHotkeyTip function (#16282)

Jeffrey Chen0c4d67698af2
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index ddc5ace6e1..fd8e713bf1 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -334,23 +334,26 @@ export const updateHotkeyAfterTip = (hotkey: string) => {
return "";
};
+const KEY_MAP = new Map([
+ ["⌘", "Ctrl"],
+ ["⌃", "Ctrl"],
+ ["⇧", "Shift"],
+ ["⌥", "Alt"],
+ ["⇥", "Tab"],
+ ["⌫", "Backspace"],
+ ["⌦", "Delete"],
+ ["↩", "Enter"],
+]);
+
// Mac,Windows 快捷键展示
export const updateHotkeyTip = (hotkey: string) => {
+ if (!hotkey) {
+ return "";
+ }
if (isMac()) {
return hotkey;
}
- const KEY_MAP = new Map(Object.entries({
- "⌘": "Ctrl",
- "⌃": "Ctrl",
- "⇧": "Shift",
- "⌥": "Alt",
- "⇥": "Tab",
- "⌫": "Backspace",
- "⌦": "Delete",
- "↩": "Enter",
- }));
-
const keys = [];
if ((hotkey.indexOf("⌘") > -1 || hotkey.indexOf("⌃") > -1)) keys.push(KEY_MAP.get("⌘"));
@@ -358,7 +361,7 @@ export const updateHotkeyTip = (hotkey: string) => {
if (hotkey.indexOf("⌥") > -1) keys.push(KEY_MAP.get("⌥"));
// 不能去最后一个,需匹配 F2
- const lastKey = hotkey.replace(/⌘|⇧|⌥|⌃/g, "");
+ const lastKey = hotkey.replace(/[⌘⇧⌥⌃]/g, "");
if (lastKey) {
keys.push(KEY_MAP.get(lastKey) || lastKey);
}