Allow default keyboard shortcuts to work on non-ASCII layouts
This commit is contained in:
parent
fdc4fc8dc9
commit
3768575bad
@ -1,6 +1,6 @@
|
|||||||
class KeyboardShortcutParser {
|
class KeyboardShortcutParser {
|
||||||
static parseShortcut(keypress) {
|
static parseShortcut(keypress) {
|
||||||
var shortcutCombo = '';
|
let shortcutCombo = '';
|
||||||
|
|
||||||
if (keypress.ctrlKey) {
|
if (keypress.ctrlKey) {
|
||||||
shortcutCombo += 'Ctrl + ';
|
shortcutCombo += 'Ctrl + ';
|
||||||
|
@ -181,19 +181,40 @@ class ActionHandler {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
isActionMatch(shortcut, event) {
|
isLatin(key) {
|
||||||
|
return 'abcdefghijklmnopqrstuvwxyz,.-+1234567890'.indexOf(key.toLocaleLowerCase()) !== -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
isActionMatchStandard(shortcut, event) {
|
||||||
return shortcut.key === event.key &&
|
return shortcut.key === event.key &&
|
||||||
shortcut.ctrlKey === event.ctrlKey &&
|
shortcut.ctrlKey === event.ctrlKey &&
|
||||||
shortcut.metaKey === event.metaKey &&
|
shortcut.metaKey === event.metaKey &&
|
||||||
shortcut.altKey === event.altKey &&
|
shortcut.altKey === event.altKey &&
|
||||||
shortcut.shiftKey === event.shiftKey
|
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) {
|
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);
|
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) {
|
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);
|
this.logger.log('info', 'keyboard', "%c[ActionHandler::execAction] found an action associated with keypress/event: ", "color: #ff0", action);
|
||||||
|
|
||||||
for (var cmd of action.cmd) {
|
for (var cmd of action.cmd) {
|
||||||
|
@ -38,6 +38,7 @@ export default {
|
|||||||
if (this.waitingForPress) {
|
if (this.waitingForPress) {
|
||||||
const shortcut = {
|
const shortcut = {
|
||||||
key: event.key,
|
key: event.key,
|
||||||
|
keyCode: event.keyCode,
|
||||||
ctrlKey: event.ctrlKey,
|
ctrlKey: event.ctrlKey,
|
||||||
metaKey: event.metaKey,
|
metaKey: event.metaKey,
|
||||||
altKey: event.altKey,
|
altKey: event.altKey,
|
||||||
|
Loading…
Reference in New Issue
Block a user