aboutsummaryrefslogtreecommitdiff
path: root/ext/js/input
diff options
context:
space:
mode:
authorKuuuube <61125188+Kuuuube@users.noreply.github.com>2024-05-14 03:01:59 -0400
committerGitHub <noreply@github.com>2024-05-14 07:01:59 +0000
commita336d176777e865228698a4daaf4b70e05309ca6 (patch)
treefa65ef053810cde03badf403585f903e9511d3f2 /ext/js/input
parente73e0817be92b86d45a0bc3cb26601186afc34f5 (diff)
Allow keyboard shortcut hotkeys to be modifiers only (#916)
* Allow hotkeys to be modifiers only * Include meta keycodes
Diffstat (limited to 'ext/js/input')
-rw-r--r--ext/js/input/hotkey-handler.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/ext/js/input/hotkey-handler.js b/ext/js/input/hotkey-handler.js
index 0f11fe87..cb95b805 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<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();
@@ -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: []};