From b43f2836c12d54a60f6250ad7d77659d29841492 Mon Sep 17 00:00:00 2001 From: handlerug Date: Sat, 25 May 2024 21:39:23 +0100 Subject: [PATCH] Make shortcuts work outside of English layout (#227) The keyboard event is tested two times: first time with the original key property, second time with the key property derived from the key code. This is done to support non-English shortcuts (which may be added by wiki administrators). --- static/shortcuts.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/static/shortcuts.js b/static/shortcuts.js index 2d05d67..e1ed6ad 100644 --- a/static/shortcuts.js +++ b/static/shortcuts.js @@ -57,9 +57,23 @@ rrh.shortcuts = { if ((!event.ctrlKey && !event.metaKey && !event.altKey) && event.target instanceof Node && isTextField(event.target)) return - let shortcut = keyEventToShortcut(event) + let possibleShortcuts = [keyEventToShortcut(event)] + if (event.code.startsWith('Key')) { + possibleShortcuts.push(keyEventToShortcut({ + ...event, + key: event.code.replace(/^Key/, '').toLowerCase(), + })) + } - if (!this.active[shortcut]) { + let shortcut = null + for (let possibleShortcut of possibleShortcuts) { + if (possibleShortcut in this.active) { + shortcut = possibleShortcut + break + } + } + + if (shortcut === null) { this._resetActive() return }