| 2 | * @param {KeyboardEvent} keystroke - https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent |
| 3 | */ |
| 4 | export function keystrokeToCanonicalCode(keystroke) { |
| 5 | // Some keyboards send RightAlt/AltGraph as LeftControl then Alt, where the |
| 6 | // Alt key has a blank code. |
| 7 | if (keystroke.key === "Alt" && keystroke.code === "") { |
| 8 | return "AltRight"; |
| 9 | } |
| 10 | |
| 11 | // Firefox calls it `OS...` instead of `Meta...`. |
| 12 | if (keystroke.code === "OSLeft") { |
| 13 | return "MetaLeft"; |
| 14 | } |
| 15 | if (keystroke.code === "OSRight") { |
| 16 | return "MetaRight"; |
| 17 | } |
| 18 | |
| 19 | return keystroke.code; |
| 20 | } |
| 21 | |
| 22 | export function isModifierCode(code) { |
| 23 | const modifierCodes = [ |