({
value: originalValue,
onChange,
onSubmit,
onExit,
onExitMessage,
onHistoryUp,
onHistoryDown,
onHistoryReset,
onClearInput,
mask = '',
multiline = false,
cursorChar,
invert,
columns,
onImagePaste: _onImagePaste,
disableCursorMovementForUpDownKeys = false,
disableEscapeDoublePress = false,
maxVisibleLines,
externalOffset,
onOffsetChange,
inputFilter,
inlineGhostText,
dim,
}: UseTextInputProps)
| 72 | } |
| 73 | |
| 74 | export function useTextInput({ |
| 75 | value: originalValue, |
| 76 | onChange, |
| 77 | onSubmit, |
| 78 | onExit, |
| 79 | onExitMessage, |
| 80 | onHistoryUp, |
| 81 | onHistoryDown, |
| 82 | onHistoryReset, |
| 83 | onClearInput, |
| 84 | mask = '', |
| 85 | multiline = false, |
| 86 | cursorChar, |
| 87 | invert, |
| 88 | columns, |
| 89 | onImagePaste: _onImagePaste, |
| 90 | disableCursorMovementForUpDownKeys = false, |
| 91 | disableEscapeDoublePress = false, |
| 92 | maxVisibleLines, |
| 93 | externalOffset, |
| 94 | onOffsetChange, |
| 95 | inputFilter, |
| 96 | inlineGhostText, |
| 97 | dim, |
| 98 | }: UseTextInputProps): TextInputState { |
| 99 | // Pre-warm the modifiers module for Apple Terminal (has internal guard, safe to call multiple times) |
| 100 | if (env.terminal === 'Apple_Terminal') { |
| 101 | prewarmModifiers() |
| 102 | } |
| 103 | |
| 104 | const offset = externalOffset |
| 105 | const setOffset = onOffsetChange |
| 106 | const cursor = Cursor.fromText(originalValue, columns, offset) |
| 107 | const { addNotification, removeNotification } = useNotifications() |
| 108 | |
| 109 | const handleCtrlC = useDoublePress( |
| 110 | show => { |
| 111 | onExitMessage?.(show, 'Ctrl-C') |
| 112 | }, |
| 113 | () => onExit?.(), |
| 114 | () => { |
| 115 | if (originalValue) { |
| 116 | onChange('') |
| 117 | setOffset(0) |
| 118 | onHistoryReset?.() |
| 119 | } |
| 120 | }, |
| 121 | ) |
| 122 | |
| 123 | // NOTE(keybindings): This escape handler is intentionally NOT migrated to the keybindings system. |
| 124 | // It's a text-level double-press escape for clearing input, not an action-level keybinding. |
| 125 | // Double-press Esc clears the input and saves to history - this is text editing behavior, |
| 126 | // not dialog dismissal, and needs the double-press safety mechanism. |
| 127 | const handleEscape = useDoublePress( |
| 128 | (show: boolean) => { |
| 129 | if (!originalValue || !show) { |
| 130 | return |
| 131 | } |
no test coverage detected