From e18e9c27507e5c00f84e2f33ee8ec23b4f14c6b3 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 18 Jun 2022 20:11:20 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/5230 --- app/src/config/keymap.ts | 2 +- app/src/constants.ts | 2 +- app/src/protyle/util/hotKey.ts | 13 ++++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/config/keymap.ts b/app/src/config/keymap.ts index d50f99da6..3e4084787 100644 --- a/app/src/config/keymap.ts +++ b/app/src/config/keymap.ts @@ -231,7 +231,7 @@ export const keymap = { keymapStr += "⌦"; } else if (event.altKey) { const codeKey = event.code.substr(event.code.length - 1, 1).toUpperCase(); - if (event.key === "Enter") { + if (event.key === "Enter" || (event.key.startsWith("F") && event.key.length > 1)) { keymapStr += event.key; } else if (event.code === "Period") { keymapStr += "."; diff --git a/app/src/constants.ts b/app/src/constants.ts index 05d313d2c..b6d9dfa2a 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -82,7 +82,7 @@ export abstract class Constants { }; // "⌘", "⇧", "⌥", "⌃" - // "⌘S", "⌘A", "⌘X", "⌘C", "⌘V", "⌘/", "⌘↑", "⌘↓", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⇧⌘⇥", "⌃⇥", "⌃⌘⇥", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧Enter", "Enter", "PageUp", "PageDown", "⌫", "⌦", "F9" 不可自定义 + // "⌘S", "⌘A", "⌘X", "⌘C", "⌘V", "⌘/", "⌘↑", "⌘↓", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⇧⌘⇥", "⌃⇥", "⌃⌘⇥", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦", "F9" 不可自定义 public static readonly SIYUAN_KEYMAP: IKeymap = { general: { enterBack: {default: "⌥←", custom: "⌥←"}, diff --git a/app/src/protyle/util/hotKey.ts b/app/src/protyle/util/hotKey.ts index d9fdc82c7..fcd5d7e20 100644 --- a/app/src/protyle/util/hotKey.ts +++ b/app/src/protyle/util/hotKey.ts @@ -18,8 +18,9 @@ export const matchHotKey = (hotKey: string, event: KeyboardEvent) => { return false; } - const hotKeys = hotKey.replace("Enter", Constants.ZWSP).split(""); - if (hotKey.endsWith("↑") || hotKey.endsWith("↓") || hotKey.endsWith("→") || hotKey.endsWith("←") || hotKey.endsWith("Enter") || hotKey.endsWith("⇥")) { + const hotKeys = hotKey.split(""); + if (hotKey.endsWith("↑") || hotKey.endsWith("↓") || hotKey.endsWith("→") || hotKey.endsWith("←") || + hotKey.endsWith("↩") || hotKey.endsWith("⇥") || hotKey.indexOf("F") > -1) { hotKeys.forEach((item, index) => { if (item === "↑") { hotKeys[index] = "ArrowUp"; @@ -31,8 +32,14 @@ export const matchHotKey = (hotKey: string, event: KeyboardEvent) => { hotKeys[index] = "ArrowRight"; } else if (item === "⇥") { hotKeys[index] = "Tab"; - } else if (item === Constants.ZWSP) { + } else if (item === "↩") { hotKeys[index] = "Enter"; + } else 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); + } } }); }