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