Vanessa 2025-11-08 23:08:50 +08:00
parent 112a0c0dac
commit 1f571ccd55

View file

@ -339,26 +339,20 @@ export const updateHotkeyTip = (hotkey: string) => {
if (!hotkey || isMac()) { if (!hotkey || isMac()) {
return hotkey; return hotkey;
} }
const KEY_MAP = new Map([
["⌘", "Ctrl"],
["⌃", "Ctrl"],
["⇧", "Shift"],
["⌥", "Alt"],
["⇥", "Tab"],
["⌫", "Backspace"],
["⌦", "Delete"],
["↩", "Enter"],
]);
const keys = []; const keys = [];
if ((hotkey.indexOf("⌘") > -1 || hotkey.indexOf("⌃") > -1)) keys.push(KEY_MAP.get("⌘")); if ((hotkey.indexOf("⌘") > -1 || hotkey.indexOf("⌃") > -1)) keys.push("Ctrl");
if (hotkey.indexOf("⇧") > -1) keys.push(KEY_MAP.get("⇧")); if (hotkey.indexOf("⇧") > -1) keys.push("Shift");
if (hotkey.indexOf("⌥") > -1) keys.push(KEY_MAP.get("⌥")); if (hotkey.indexOf("⌥") > -1) keys.push( "Alt");
// 不能去最后一个,需匹配 F2 // 不能去最后一个,需匹配 F2
const lastKey = hotkey.replace(/[⌘⇧⌥⌃]/g, ""); const lastKey = hotkey.replace(/[⌘⇧⌥⌃]/g, "");
if (lastKey) { if (lastKey) {
keys.push(KEY_MAP.get(lastKey) || lastKey); keys.push({
"⇥": "Tab",
"⌫": "Backspace",
"⌦": "Delete",
"↩": "Enter"
}[lastKey] || lastKey);
} }
return keys.join("+"); return keys.join("+");
}; };