Allow default keyboard shortcuts to work on non-ASCII layouts

This commit is contained in:
Tamius Han 2019-10-22 01:33:56 +02:00
parent fdc4fc8dc9
commit 3768575bad
3 changed files with 25 additions and 3 deletions

View File

@ -1,6 +1,6 @@
class KeyboardShortcutParser {
static parseShortcut(keypress) {
var shortcutCombo = '';
let shortcutCombo = '';
if (keypress.ctrlKey) {
shortcutCombo += 'Ctrl + ';

View File

@ -181,19 +181,40 @@ class ActionHandler {
return false;
}
isActionMatch(shortcut, event) {
isLatin(key) {
return 'abcdefghijklmnopqrstuvwxyz,.-+1234567890'.indexOf(key.toLocaleLowerCase()) !== -1;
}
isActionMatchStandard(shortcut, event) {
return shortcut.key === event.key &&
shortcut.ctrlKey === event.ctrlKey &&
shortcut.metaKey === event.metaKey &&
shortcut.altKey === event.altKey &&
shortcut.shiftKey === event.shiftKey
}
isActionMatchKeycode(shortcut, event) {
return shortcut.keyCode === event.key &&
shortcut.ctrlKey === event.ctrlKey &&
shortcut.metaKey === event.metaKey &&
shortcut.altKey === event.altKey &&
shortcut.shiftKey === event.shiftKey
}
isActionMatch(shortcut, event, isLatin = true) {
// ASCII and symbols fall back to keycode matching, because we don't know for sure that
// regular matching by key is going to work
return isLatin ?
this.isActionMatchStandard(shortcut, event) :
this.isActionMatchStandard(shortcut, event) || this.isActionMatchKeycode(shortcut, event);
}
execAction(actions, event, videoData) {
this.logger.log('info', 'keyboard', "%c[ActionHandler::execAction] Trying to find and execute action for event. Actions/event: ", "color: #ff0", actions, event);
const isLatin = this.isLatin(event.key);
for (var action of actions) {
if (this.isActionMatch(action.shortcut, event)) {
if (this.isActionMatch(action.shortcut, event, isLatin)) {
this.logger.log('info', 'keyboard', "%c[ActionHandler::execAction] found an action associated with keypress/event: ", "color: #ff0", action);
for (var cmd of action.cmd) {

View File

@ -38,6 +38,7 @@ export default {
if (this.waitingForPress) {
const shortcut = {
key: event.key,
keyCode: event.keyCode,
ctrlKey: event.ctrlKey,
metaKey: event.metaKey,
altKey: event.altKey,