mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
♻️ Refactor updateHotkeyTip function (#16282)
This commit is contained in:
parent
0f055f1f7c
commit
0c4d67698a
1 changed files with 15 additions and 12 deletions
|
|
@ -334,23 +334,26 @@ export const updateHotkeyAfterTip = (hotkey: string) => {
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const KEY_MAP = new Map([
|
||||||
|
["⌘", "Ctrl"],
|
||||||
|
["⌃", "Ctrl"],
|
||||||
|
["⇧", "Shift"],
|
||||||
|
["⌥", "Alt"],
|
||||||
|
["⇥", "Tab"],
|
||||||
|
["⌫", "Backspace"],
|
||||||
|
["⌦", "Delete"],
|
||||||
|
["↩", "Enter"],
|
||||||
|
]);
|
||||||
|
|
||||||
// Mac,Windows 快捷键展示
|
// Mac,Windows 快捷键展示
|
||||||
export const updateHotkeyTip = (hotkey: string) => {
|
export const updateHotkeyTip = (hotkey: string) => {
|
||||||
|
if (!hotkey) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
if (isMac()) {
|
if (isMac()) {
|
||||||
return hotkey;
|
return hotkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
const KEY_MAP = new Map(Object.entries({
|
|
||||||
"⌘": "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(KEY_MAP.get("⌘"));
|
||||||
|
|
@ -358,7 +361,7 @@ export const updateHotkeyTip = (hotkey: string) => {
|
||||||
if (hotkey.indexOf("⌥") > -1) keys.push(KEY_MAP.get("⌥"));
|
if (hotkey.indexOf("⌥") > -1) keys.push(KEY_MAP.get("⌥"));
|
||||||
|
|
||||||
// 不能去最后一个,需匹配 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(KEY_MAP.get(lastKey) || lastKey);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue