Browse Source

dvorak shortcuts support - fixes #2544, fixes #2670

Eugene Pankov 4 years ago
parent
commit
4a97cc4383
1 changed files with 25 additions and 17 deletions
  1. 25 17
      terminus-core/src/services/hotkeys.util.ts

+ 25 - 17
terminus-core/src/services/hotkeys.util.ts

@@ -10,6 +10,8 @@ export const altKeyName = {
     linux: 'Alt',
 }[process.platform]
 
+const REGEX_LATIN_KEYNAME = /^[A-Za-z]$/
+
 export function stringifyKeySequence (events: KeyboardEvent[]): string[] {
     const items: string[] = []
     events = events.slice()
@@ -37,23 +39,29 @@ export function stringifyKeySequence (events: KeyboardEvent[]): string[] {
             }
 
             let key = event.code
-            key = key.replace('Key', '')
-            key = key.replace('Arrow', '')
-            key = key.replace('Digit', '')
-            key = {
-                Comma: ',',
-                Period: '.',
-                Slash: '/',
-                Backslash: '\\',
-                IntlBackslash: '\\',
-                Backquote: '`',
-                Minus: '-',
-                Equal: '=',
-                Semicolon: ';',
-                Quote: '\'',
-                BracketLeft: '[',
-                BracketRight: ']',
-            }[key] || key
+            if (REGEX_LATIN_KEYNAME.test(event.key)) {
+                // Handle Dvorak etc via the reported "character" instead of the scancode
+                key = event.key.toUpperCase()
+            } else {
+                key = key.replace('Key', '')
+                key = key.replace('Arrow', '')
+                key = key.replace('Digit', '')
+                key = {
+                    Comma: ',',
+                    Period: '.',
+                    Slash: '/',
+                    Backslash: '\\',
+                    IntlBackslash: '\\',
+                    Backquote: '`',
+                    Minus: '-',
+                    Equal: '=',
+                    Semicolon: ';',
+                    Quote: '\'',
+                    BracketLeft: '[',
+                    BracketRight: ']',
+                }[key] || key
+            }
+
             itemKeys.push(key)
             items.push(itemKeys.join('-'))
         }