1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 03:36:16 +00:00

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).
This commit is contained in:
handlerug 2024-05-25 21:39:23 +01:00 committed by GitHub
parent afe2f0c9e2
commit b43f2836c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
}