|
1 | 1 | import {NormalizedSequenceString} from './sequence.js' |
2 | 2 | import {macosSymbolLayerKeys} from './macos-symbol-layer.js' |
| 3 | +import {macosUppercaseLayerKeys} from './macos-uppercase-layer.js' |
3 | 4 |
|
4 | 5 | const normalizedHotkeyBrand = Symbol('normalizedHotkey') |
5 | 6 |
|
@@ -47,9 +48,19 @@ export function eventToHotkeyString( |
47 | 48 | } |
48 | 49 |
|
49 | 50 | if (!modifierKeyNames.includes(key)) { |
50 | | - const nonOptionPlaneKey = |
| 51 | + // MacOS outputs symbols when `Alt` is held, so we map them back to the key symbol if we can |
| 52 | + const altNormalizedKey = |
51 | 53 | hotkeyString.includes('Alt') && matchApplePlatform.test(platform) ? macosSymbolLayerKeys[key] ?? key : key |
52 | | - const syntheticKey = syntheticKeyNames[nonOptionPlaneKey] ?? nonOptionPlaneKey |
| 54 | + |
| 55 | + // MacOS outputs lowercase characters when `Command+Shift` is held, so we map them back to uppercase if we can |
| 56 | + const shiftNormalizedKey = |
| 57 | + hotkeyString.includes('Shift') && matchApplePlatform.test(platform) |
| 58 | + ? macosUppercaseLayerKeys[altNormalizedKey] ?? altNormalizedKey |
| 59 | + : altNormalizedKey |
| 60 | + |
| 61 | + // Some symbols can't be used because of hotkey string format, so we replace them with 'synthetic' named keys |
| 62 | + const syntheticKey = syntheticKeyNames[shiftNormalizedKey] ?? shiftNormalizedKey |
| 63 | + |
53 | 64 | hotkeyString.push(syntheticKey) |
54 | 65 | } |
55 | 66 |
|
@@ -84,12 +95,12 @@ function localizeMod(hotkey: string, platform: string = navigator.platform): str |
84 | 95 |
|
85 | 96 | function sortModifiers(hotkey: string): string { |
86 | 97 | const key = hotkey.split('+').pop() |
87 | | - const modifiers = [] |
| 98 | + const modifiers: string[] = [] |
88 | 99 | for (const modifier of ['Control', 'Alt', 'Meta', 'Shift']) { |
89 | 100 | if (hotkey.includes(modifier)) { |
90 | 101 | modifiers.push(modifier) |
91 | 102 | } |
92 | 103 | } |
93 | | - modifiers.push(key) |
| 104 | + if (key) modifiers.push(key) |
94 | 105 | return modifiers.join('+') |
95 | 106 | } |
0 commit comments