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

Function useTextInput

src/hooks/useTextInput.ts:74–530  ·  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

72}
73
74export 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 }

Callers 2

TextInputFunction · 0.85
useVimInputFunction · 0.85

Calls 15

prewarmModifiersFunction · 0.85
useNotificationsFunction · 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