Skip to content

Commit

Permalink
Allow keyboard shortcut hotkeys to be modifiers only (#916)
Browse files Browse the repository at this point in the history
* Allow hotkeys to be modifiers only

* Include meta keycodes
  • Loading branch information
Kuuuube committed May 14, 2024
1 parent e73e081 commit a336d17
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ext/js/input/hotkey-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class HotkeyHandler extends EventDispatcher {
super();
/** @type {Map<string, (argument: unknown) => (boolean|void)>} */
this._actions = new Map();
/** @type {Map<string, import('hotkey-handler').HotkeyHandlers>} */
/** @type {Map<(string | null), import('hotkey-handler').HotkeyHandlers>} */
this._hotkeys = new Map();
/** @type {Map<import('settings').InputsHotkeyScope, import('settings').InputsHotkeyOptions[]>} */
this._hotkeyRegistrations = new Map();
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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: []};
Expand Down

0 comments on commit a336d17

Please sign in to comment.