refactor hotkey setting & add A hotkey (#676)

This commit is contained in:
an-lee
2024-06-14 10:55:32 +08:00
committed by GitHub
parent 91bb441ebd
commit 448ece4e7d
6 changed files with 59 additions and 26 deletions

View File

@@ -14,8 +14,8 @@ function isShortcutValid(shortcut: string) {
const keys = shortcut.toLowerCase().split("+");
const modifierCount = keys.filter((key) => modifiers.includes(key)).length;
const normalKeyCount = keys.length - modifierCount;
// Validation rule: At most one modifier key, and at most one regular key
return modifierCount <= 1 && normalKeyCount === 1;
// Validation rule: At most two modifier key, and at most one regular key
return modifierCount <= 2 && normalKeyCount === 1;
}
function mergeWithPreference(
@@ -37,7 +37,7 @@ function mergeWithPreference(
return c;
}
const ControlOrCommand = navigator.platform.includes("Mac")
const ControlOrCommand = navigator.userAgent.includes("Mac")
? "Meta"
: "Control";
@@ -52,6 +52,7 @@ const defaultKeyMap = {
PlayPreviousSegment: "P",
PlayNextSegment: "N",
Compare: "C",
PronunciationAssessment: "A",
// dev tools
OpenDevTools: `${ControlOrCommand}+Shift+I`,
};
@@ -89,9 +90,8 @@ const initialState: HotkeysSettingsProviderState = {
isRecording: false,
};
export const HotKeysSettingsProviderContext = createContext<
HotkeysSettingsProviderState
>(initialState);
export const HotKeysSettingsProviderContext =
createContext<HotkeysSettingsProviderState>(initialState);
const HotKeysSettingsSystemSettings = ({
currentHotkeys,
@@ -168,7 +168,8 @@ export const HotKeysSettingsProvider = ({
data: string | string[];
input: string;
} | void> => {
const str = [...recordedHotkeys].join("+");
const keys = [...recordedHotkeys].slice(0, 3).filter(Boolean);
const str = keys.join("+");
const newMap = {
...currentHotkeys,
[keyName]: str,