Skip to content

Commit a9bb52e

Browse files
Revert "fix(frontend): 直前のパターンを記録するように"
This reverts commit 5372b25.
1 parent bdac342 commit a9bb52e

File tree

1 file changed

+4
-30
lines changed

1 file changed

+4
-30
lines changed

packages/frontend/src/scripts/hotkey.ts

+4-30
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ const MODIFIER_KEYS = ['ctrl', 'alt', 'shift'];
4545
const IGNORE_ELEMENTS = ['input', 'textarea'];
4646
//#endregion
4747

48-
//#region store
49-
let latestHotkey: Pattern & { callback: CallbackFunction } | null = null;
50-
//#endregion
51-
5248
//#region impl
5349
export const makeHotkey = (keymap: Keymap) => {
5450
const actions = parseKeymap(keymap);
@@ -58,12 +54,11 @@ export const makeHotkey = (keymap: Keymap) => {
5854
if (IGNORE_ELEMENTS.includes(document.activeElement.tagName.toLowerCase())) return;
5955
if (getHTMLElementOrNull(document.activeElement)?.isContentEditable) return;
6056
}
61-
for (const action of actions) {
62-
if (matchPatterns(ev, action)) {
57+
for (const { patterns, callback, options } of actions) {
58+
if (matchPatterns(ev, patterns, options)) {
6359
ev.preventDefault();
6460
ev.stopPropagation();
65-
action.callback(ev);
66-
storePattern(ev, action.callback);
61+
callback(ev);
6762
}
6863
}
6964
};
@@ -108,21 +103,10 @@ const parseOptions = (rawCallback: Keymap[keyof Keymap]) => {
108103
return { ...defaultOptions } as const satisfies Action['options'];
109104
};
110105

111-
const matchPatterns = (ev: KeyboardEvent, action: Action) => {
112-
const { patterns, options, callback } = action;
106+
const matchPatterns = (ev: KeyboardEvent, patterns: Action['patterns'], options: Action['options']) => {
113107
if (ev.repeat && !options.allowRepeat) return false;
114108
const key = ev.key.toLowerCase();
115109
return patterns.some(({ which, ctrl, shift, alt }) => {
116-
if (
117-
latestHotkey != null &&
118-
latestHotkey.which.includes(key) &&
119-
latestHotkey.ctrl === ctrl &&
120-
latestHotkey.alt === alt &&
121-
latestHotkey.shift === shift &&
122-
latestHotkey.callback === callback
123-
) {
124-
return false;
125-
}
126110
if (!which.includes(key)) return false;
127111
if (ctrl !== (ev.ctrlKey || ev.metaKey)) return false;
128112
if (alt !== ev.altKey) return false;
@@ -131,16 +115,6 @@ const matchPatterns = (ev: KeyboardEvent, action: Action) => {
131115
});
132116
};
133117

134-
const storePattern = (ev: KeyboardEvent, callback: CallbackFunction) => {
135-
latestHotkey = {
136-
which: [ev.key.toLowerCase()],
137-
ctrl: ev.ctrlKey || ev.metaKey,
138-
alt: ev.altKey,
139-
shift: ev.shiftKey,
140-
callback,
141-
};
142-
};
143-
144118
const parseKeyCode = (input?: string | null) => {
145119
if (input == null) return [];
146120
const raw = getValueByKey(KEY_ALIASES, input);

0 commit comments

Comments
 (0)