(e: React.KeyboardEvent<HTMLDivElement>)
| 113 | }, [visible, visibleActive]) |
| 114 | |
| 115 | const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>): void => { |
| 116 | if (e.key === 'Escape') { |
| 117 | e.preventDefault() |
| 118 | e.stopPropagation() |
| 119 | if (query) setQuery('') |
| 120 | else onClose() |
| 121 | return |
| 122 | } |
| 123 | if ( |
| 124 | e.key === 'ArrowDown' || |
| 125 | (!e.metaKey && !e.ctrlKey && !e.altKey && e.key === 'j') |
| 126 | ) { |
| 127 | e.preventDefault() |
| 128 | e.stopPropagation() |
| 129 | setVisibleActive((i) => stepVisible(visible, i, 1)) |
| 130 | return |
| 131 | } |
| 132 | if ( |
| 133 | e.key === 'ArrowUp' || |
| 134 | (!e.metaKey && !e.ctrlKey && !e.altKey && e.key === 'k') |
| 135 | ) { |
| 136 | e.preventDefault() |
| 137 | e.stopPropagation() |
| 138 | setVisibleActive((i) => stepVisible(visible, i, -1)) |
| 139 | return |
| 140 | } |
| 141 | if (e.ctrlKey && !e.metaKey && !e.altKey && (e.key === 'n' || e.key === 'N')) { |
| 142 | e.preventDefault() |
| 143 | e.stopPropagation() |
| 144 | setVisibleActive((i) => stepVisible(visible, i, 1)) |
| 145 | return |
| 146 | } |
| 147 | if (e.ctrlKey && !e.metaKey && !e.altKey && (e.key === 'p' || e.key === 'P')) { |
| 148 | e.preventDefault() |
| 149 | e.stopPropagation() |
| 150 | setVisibleActive((i) => stepVisible(visible, i, -1)) |
| 151 | return |
| 152 | } |
| 153 | if (e.key === 'Enter') { |
| 154 | e.preventDefault() |
| 155 | e.stopPropagation() |
| 156 | const entry = visible[visibleActive] |
| 157 | if (entry && entry.item.kind !== 'separator' && !entry.item.disabled) { |
| 158 | onClose() |
| 159 | void Promise.resolve(entry.item.onSelect?.()) |
| 160 | } |
| 161 | return |
| 162 | } |
| 163 | if (e.key === 'Backspace') { |
| 164 | if (query) { |
| 165 | e.preventDefault() |
| 166 | e.stopPropagation() |
| 167 | setQuery((q) => q.slice(0, -1)) |
| 168 | } |
| 169 | return |
| 170 | } |
| 171 | if (e.metaKey || e.ctrlKey || e.altKey) return |
| 172 | if (e.key.length === 1) { |
nothing calls this directly
no test coverage detected