mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
parent
e996975722
commit
efffe304e0
1 changed files with 33 additions and 17 deletions
|
|
@ -76,23 +76,39 @@ export const updateHotkeyTip = (hotkey: string) => {
|
|||
if (/Mac/.test(navigator.platform) || navigator.platform === "iPhone") {
|
||||
return hotkey;
|
||||
}
|
||||
if (hotkey.startsWith("⌘")) {
|
||||
hotkey = hotkey.replace("⌘", "⌘+");
|
||||
} else if (hotkey.startsWith("⌥") && hotkey.substr(1, 1) !== "⌘") {
|
||||
hotkey = hotkey.replace("⌥", "⌥+");
|
||||
} else if (hotkey.startsWith("⇧⌘") || hotkey.startsWith("⌥⌘")) {
|
||||
hotkey = hotkey.replace("⇧⌘", "⌘+⇧+").replace("⌥⌘", "⌘+⌥+");
|
||||
} else if (hotkey.startsWith("⇧")) {
|
||||
hotkey = hotkey.replace("⇧", "⇧+");
|
||||
|
||||
const KEY_MAP = new Map(Object.entries({
|
||||
"⌘": "Ctrl",
|
||||
"⇧": "Shift",
|
||||
"⌥": "Alt",
|
||||
"⇥": "Tab",
|
||||
"⌫": "Backspace",
|
||||
"⌦": "Delete",
|
||||
"↩": "Enter",
|
||||
}));
|
||||
const SHIFT_KEY_MAP = new Map(Object.entries({
|
||||
";": ":",
|
||||
"=": "+",
|
||||
"-": "_",
|
||||
".": ">",
|
||||
}));
|
||||
|
||||
let keys = [];
|
||||
|
||||
if (hotkey.indexOf("⌘") > -1) keys.push(KEY_MAP.get("⌘"));
|
||||
if (hotkey.indexOf("⇧") > -1) keys.push(KEY_MAP.get("⇧"));
|
||||
if (hotkey.indexOf("⌥") > -1) keys.push(KEY_MAP.get("⌥"));
|
||||
|
||||
const lastKey = hotkey.charAt(hotkey.length - 1);
|
||||
if ("⌘⇧⌥".indexOf(lastKey) < 0) {
|
||||
keys.push(
|
||||
KEY_MAP.get(lastKey)
|
||||
|| (hotkey.indexOf("⇧") > -1 && SHIFT_KEY_MAP.get(lastKey))
|
||||
|| lastKey
|
||||
);
|
||||
}
|
||||
hotkey = hotkey.replace("⌘", "Ctrl").replace("⇧", "Shift")
|
||||
.replace("⌥", "Alt").replace("⇥", "Tab")
|
||||
.replace("⌫", "Backspace").replace("⌦", "Delete")
|
||||
.replace("↩", "Enter");
|
||||
if (hotkey.indexOf("Shift") > -1) {
|
||||
hotkey = hotkey.replace(";", ":").replace("=", "+").replace("-", "_").replace(".", ">");
|
||||
}
|
||||
return hotkey;
|
||||
|
||||
return keys.join("+");
|
||||
};
|
||||
|
||||
export const hotKey2Electron = (key: string) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue