* Serializes a parsed hotkey to the canonical string form used for registration * and storage: `Mod` first when the platform allows, then `Alt`, then `Shift`; * otherwise full `Control+Alt+Shift+Meta` order.
( parsed: ParsedHotkey, platform: 'mac' | 'windows' | 'linux', )
| 144 | * otherwise full `Control+Alt+Shift+Meta` order. |
| 145 | */ |
| 146 | function normalizedHotkeyStringFromParsed( |
| 147 | parsed: ParsedHotkey, |
| 148 | platform: 'mac' | 'windows' | 'linux', |
| 149 | ): Hotkey { |
| 150 | const canUseMod = |
| 151 | platform === 'mac' |
| 152 | ? parsed.meta && !parsed.ctrl |
| 153 | : parsed.ctrl && !parsed.meta |
| 154 | |
| 155 | const parts: Array<string> = [] |
| 156 | |
| 157 | if (canUseMod) { |
| 158 | parts.push('Mod') |
| 159 | if (parsed.alt) { |
| 160 | parts.push('Alt') |
| 161 | } |
| 162 | if (parsed.shift) { |
| 163 | parts.push('Shift') |
| 164 | } |
| 165 | } else { |
| 166 | for (const modifier of MODIFIER_ORDER) { |
| 167 | if (parsed.modifiers.includes(modifier)) { |
| 168 | parts.push(modifier) |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | parts.push(normalizeKeyName(parsed.key)) |
| 174 | return parts.join('+') as Hotkey |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Normalizes a hotkey string to its canonical form. |
no test coverage detected
searching dependent graphs…