* Append a keystroke to the typeahead buffer (reset after 2s idle) and * call `onMatch` with the index of the first label that prefix-matches. * Shared by boolean y/n, enum accordion, and multi-select accordion.
(char: string, labels: string[], onMatch: (index: number) => void)
| 457 | * Shared by boolean y/n, enum accordion, and multi-select accordion. |
| 458 | */ |
| 459 | function runTypeahead(char: string, labels: string[], onMatch: (index: number) => void) { |
| 460 | const ta_0 = enumTypeaheadRef.current; |
| 461 | if (ta_0.timer !== undefined) clearTimeout(ta_0.timer); |
| 462 | ta_0.buffer += char.toLowerCase(); |
| 463 | ta_0.timer = setTimeout(resetTypeahead, 2000, ta_0); |
| 464 | const match = labels.findIndex(l => l.startsWith(ta_0.buffer)); |
| 465 | if (match !== -1) onMatch(match); |
| 466 | } |
| 467 | |
| 468 | // Esc while a field is focused: cancel the dialog. |
| 469 | // Uses Settings context (escape-only, no 'n' key) since Dialog's |
no outgoing calls
no test coverage detected