* Validate a single keystroke string and return any parse errors.
(keystroke: string)
| 91 | * Validate a single keystroke string and return any parse errors. |
| 92 | */ |
| 93 | function validateKeystroke(keystroke: string): KeybindingWarning | null { |
| 94 | const parts = keystroke.toLowerCase().split('+') |
| 95 | |
| 96 | for (const part of parts) { |
| 97 | const trimmed = part.trim() |
| 98 | if (!trimmed) { |
| 99 | return { |
| 100 | type: 'parse_error', |
| 101 | severity: 'error', |
| 102 | message: `Empty key part in "${keystroke}"`, |
| 103 | key: keystroke, |
| 104 | suggestion: 'Remove extra "+" characters', |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // Try to parse and see if it fails |
| 110 | const parsed = parseKeystroke(keystroke) |
| 111 | if ( |
| 112 | !parsed.key && |
| 113 | !parsed.ctrl && |
| 114 | !parsed.alt && |
| 115 | !parsed.shift && |
| 116 | !parsed.meta |
| 117 | ) { |
| 118 | return { |
| 119 | type: 'parse_error', |
| 120 | severity: 'error', |
| 121 | message: `Could not parse keystroke "${keystroke}"`, |
| 122 | key: keystroke, |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | return null |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Validate a keybinding block from user config. |
no test coverage detected