diff --git a/ext/js/input/hotkey-handler.js b/ext/js/input/hotkey-handler.js index 0f11fe87c4..cb95b805fd 100644 --- a/ext/js/input/hotkey-handler.js +++ b/ext/js/input/hotkey-handler.js @@ -32,7 +32,7 @@ export class HotkeyHandler extends EventDispatcher { super(); /** @type {Map (boolean|void)>} */ this._actions = new Map(); - /** @type {Map} */ + /** @type {Map<(string | null), import('hotkey-handler').HotkeyHandlers>} */ this._hotkeys = new Map(); /** @type {Map} */ this._hotkeyRegistrations = new Map(); @@ -171,7 +171,11 @@ export class HotkeyHandler extends EventDispatcher { * @param {KeyboardEvent} event */ _onKeyDown(event) { - const hotkeyInfo = this._hotkeys.get(event.code); + let hotkeyInfo = this._hotkeys.get(event.code); + const modifierKeycodes = ['ControlLeft', 'ControlRight', 'ShiftLeft', 'ShiftRight', 'AltLeft', 'AltRight', 'MetaLeft', 'MetaRight']; + if (modifierKeycodes.includes(event.code)) { + hotkeyInfo = this._hotkeys.get(null); // Hotkeys with only modifiers are stored as null + } if (typeof hotkeyInfo !== 'undefined') { const eventModifiers = getActiveModifiers(event); if (this._invokeHandlers(eventModifiers, hotkeyInfo, event.key)) { @@ -228,8 +232,7 @@ export class HotkeyHandler extends EventDispatcher { this._hotkeys.clear(); for (const [scope, registrations] of this._hotkeyRegistrations.entries()) { for (const {action, argument, key, modifiers, scopes, enabled} of registrations) { - if (!(enabled && key !== null && action !== '' && scopes.includes(scope))) { continue; } - + if (!(enabled && (key !== null || modifiers !== null) && action !== '' && scopes.includes(scope))) { continue; } let hotkeyInfo = this._hotkeys.get(key); if (typeof hotkeyInfo === 'undefined') { hotkeyInfo = {handlers: []};