diff options
| author | Kagami Sascha Rosylight <saschanaz@outlook.com> | 2023-03-01 07:24:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-01 15:24:09 +0900 |
| commit | 6d82371449cc97f1ee8a7425b17ec536a3095640 (patch) | |
| tree | 199afc9df4d21d20ab5e780b46a42a8d89a006bc /packages/frontend/src/scripts | |
| parent | refactor: plugin.tsの型を修正する (#10027) (diff) | |
| download | sharkey-6d82371449cc97f1ee8a7425b17ec536a3095640.tar.gz sharkey-6d82371449cc97f1ee8a7425b17ec536a3095640.tar.bz2 sharkey-6d82371449cc97f1ee8a7425b17ec536a3095640.zip | |
fix(frontend): read KeyboardEvent.key instead of which/code (#10083)
Diffstat (limited to 'packages/frontend/src/scripts')
| -rw-r--r-- | packages/frontend/src/scripts/hotkey.ts | 6 | ||||
| -rw-r--r-- | packages/frontend/src/scripts/keycode.ts | 15 |
2 files changed, 3 insertions, 18 deletions
diff --git a/packages/frontend/src/scripts/hotkey.ts b/packages/frontend/src/scripts/hotkey.ts index 4a0ded637d..b7238016c6 100644 --- a/packages/frontend/src/scripts/hotkey.ts +++ b/packages/frontend/src/scripts/hotkey.ts @@ -53,10 +53,10 @@ const parseKeymap = (keymap: Keymap) => Object.entries(keymap).map(([patterns, c return result; }); -const ignoreElemens = ['input', 'textarea']; +const ignoreElements = ['input', 'textarea']; function match(ev: KeyboardEvent, patterns: Action['patterns']): boolean { - const key = ev.code.toLowerCase(); + const key = ev.key.toLowerCase(); return patterns.some(pattern => pattern.which.includes(key) && pattern.ctrl === ev.ctrlKey && pattern.shift === ev.shiftKey && @@ -70,7 +70,7 @@ export const makeHotkey = (keymap: Keymap) => { return (ev: KeyboardEvent) => { if (document.activeElement) { - if (ignoreElemens.some(el => document.activeElement!.matches(el))) return; + if (ignoreElements.some(el => document.activeElement!.matches(el))) return; if (document.activeElement.attributes['contenteditable']) return; } diff --git a/packages/frontend/src/scripts/keycode.ts b/packages/frontend/src/scripts/keycode.ts index 69f6a82803..35813edbd5 100644 --- a/packages/frontend/src/scripts/keycode.ts +++ b/packages/frontend/src/scripts/keycode.ts @@ -16,18 +16,3 @@ export const aliases = { 'right': 'ArrowRight', 'plus': ['NumpadAdd', 'Semicolon'], }; - -/*! -* Programmatically add the following -*/ - -// lower case chars -for (let i = 97; i < 123; i++) { - const char = String.fromCharCode(i); - aliases[char] = `Key${char.toUpperCase()}`; -} - -// numbers -for (let i = 0; i < 10; i++) { - aliases[i] = [`Numpad${i}`, `Digit${i}`]; -} |