From a9bb52e799e110927ad92cd8f26af980819334e1 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Wed, 10 Jul 2024 00:01:24 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"fix(frontend):=20=E7=9B=B4=E5=89=8D?= =?UTF-8?q?=E3=81=AE=E3=83=91=E3=82=BF=E3=83=BC=E3=83=B3=E3=82=92=E8=A8=98?= =?UTF-8?q?=E9=8C=B2=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 5372b2594023952cff34aa62253ed4efef15b5dd. --- packages/frontend/src/scripts/hotkey.ts | 34 +++---------------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/packages/frontend/src/scripts/hotkey.ts b/packages/frontend/src/scripts/hotkey.ts index 073d416263..b47a80fbee 100644 --- a/packages/frontend/src/scripts/hotkey.ts +++ b/packages/frontend/src/scripts/hotkey.ts @@ -45,10 +45,6 @@ const MODIFIER_KEYS = ['ctrl', 'alt', 'shift']; const IGNORE_ELEMENTS = ['input', 'textarea']; //#endregion -//#region store -let latestHotkey: Pattern & { callback: CallbackFunction } | null = null; -//#endregion - //#region impl export const makeHotkey = (keymap: Keymap) => { const actions = parseKeymap(keymap); @@ -58,12 +54,11 @@ export const makeHotkey = (keymap: Keymap) => { if (IGNORE_ELEMENTS.includes(document.activeElement.tagName.toLowerCase())) return; if (getHTMLElementOrNull(document.activeElement)?.isContentEditable) return; } - for (const action of actions) { - if (matchPatterns(ev, action)) { + for (const { patterns, callback, options } of actions) { + if (matchPatterns(ev, patterns, options)) { ev.preventDefault(); ev.stopPropagation(); - action.callback(ev); - storePattern(ev, action.callback); + callback(ev); } } }; @@ -108,21 +103,10 @@ const parseOptions = (rawCallback: Keymap[keyof Keymap]) => { return { ...defaultOptions } as const satisfies Action['options']; }; -const matchPatterns = (ev: KeyboardEvent, action: Action) => { - const { patterns, options, callback } = action; +const matchPatterns = (ev: KeyboardEvent, patterns: Action['patterns'], options: Action['options']) => { if (ev.repeat && !options.allowRepeat) return false; const key = ev.key.toLowerCase(); return patterns.some(({ which, ctrl, shift, alt }) => { - if ( - latestHotkey != null && - latestHotkey.which.includes(key) && - latestHotkey.ctrl === ctrl && - latestHotkey.alt === alt && - latestHotkey.shift === shift && - latestHotkey.callback === callback - ) { - return false; - } if (!which.includes(key)) return false; if (ctrl !== (ev.ctrlKey || ev.metaKey)) return false; if (alt !== ev.altKey) return false; @@ -131,16 +115,6 @@ const matchPatterns = (ev: KeyboardEvent, action: Action) => { }); }; -const storePattern = (ev: KeyboardEvent, callback: CallbackFunction) => { - latestHotkey = { - which: [ev.key.toLowerCase()], - ctrl: ev.ctrlKey || ev.metaKey, - alt: ev.altKey, - shift: ev.shiftKey, - callback, - }; -}; - const parseKeyCode = (input?: string | null) => { if (input == null) return []; const raw = getValueByKey(KEY_ALIASES, input);