(e: KeyboardEvent)
| 102 | }, []) |
| 103 | |
| 104 | const handleKeyDown = (e: KeyboardEvent): void => { |
| 105 | if (!isActive) return |
| 106 | |
| 107 | const cursor = Cursor.fromText(query, effectiveColumns, cursorOffset) |
| 108 | |
| 109 | // Check passthrough ctrl keys |
| 110 | if (e.ctrl && passthroughCtrlKeys.includes(e.key.toLowerCase())) { |
| 111 | return |
| 112 | } |
| 113 | |
| 114 | // Reset kill accumulation for non-kill keys |
| 115 | if (!isKillKey(e)) { |
| 116 | resetKillAccumulation() |
| 117 | } |
| 118 | |
| 119 | // Reset yank state for non-yank keys |
| 120 | if (!isYankKey(e)) { |
| 121 | resetYankState() |
| 122 | } |
| 123 | |
| 124 | // Exit conditions |
| 125 | if (e.key === 'return' || e.key === 'down') { |
| 126 | e.preventDefault() |
| 127 | onExit() |
| 128 | return |
| 129 | } |
| 130 | if (e.key === 'up') { |
| 131 | e.preventDefault() |
| 132 | if (onExitUp) { |
| 133 | onExitUp() |
| 134 | } |
| 135 | return |
| 136 | } |
| 137 | if (e.key === 'escape') { |
| 138 | e.preventDefault() |
| 139 | if (onCancel) { |
| 140 | onCancel() |
| 141 | } else if (query.length > 0) { |
| 142 | setQueryState('') |
| 143 | setCursorOffset(0) |
| 144 | } else { |
| 145 | onExit() |
| 146 | } |
| 147 | return |
| 148 | } |
| 149 | |
| 150 | // Backspace/Delete |
| 151 | if (e.key === 'backspace') { |
| 152 | e.preventDefault() |
| 153 | if (e.meta) { |
| 154 | // Meta+Backspace: kill word before |
| 155 | const { cursor: newCursor, killed } = cursor.deleteWordBefore() |
| 156 | pushToKillRing(killed, 'prepend') |
| 157 | setQueryState(newCursor.text) |
| 158 | setCursorOffset(newCursor.offset) |
| 159 | return |
| 160 | } |
| 161 | if (query.length === 0) { |
no test coverage detected