MCPcopy
hub / github.com/codeaashu/claude-code / useTextInput

Function useTextInput

src/hooks/useTextInput.ts:73–529  ·  view source on GitHub ↗
({
  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)

Source from the content-addressed store, hash-verified

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

Callers 2

TextInputFunction · 0.85
useVimInputFunction · 0.85

Calls 15

prewarmModifiersFunction · 0.85
useDoublePressFunction · 0.85
onExitFunction · 0.85
addToHistoryFunction · 0.85
mapInputFunction · 0.85
downOrHistoryDownFunction · 0.85
upOrHistoryUpFunction · 0.85
fromTextMethod · 0.80
startOfLineMethod · 0.80
leftMethod · 0.80
endOfLineMethod · 0.80
rightMethod · 0.80

Tested by

no test coverage detected