MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / useSearchInput

Function useSearchInput

src/hooks/useSearchInput.ts:83–363  ·  view source on GitHub ↗
({
  isActive,
  onExit,
  onCancel,
  onExitUp,
  columns,
  passthroughCtrlKeys = [],
  initialQuery = '',
  backspaceExitsOnEmpty = true,
}: UseSearchInputOptions)

Source from the content-addressed store, hash-verified

81])
82
83export function useSearchInput({
84 isActive,
85 onExit,
86 onCancel,
87 onExitUp,
88 columns,
89 passthroughCtrlKeys = [],
90 initialQuery = '',
91 backspaceExitsOnEmpty = true,
92}: UseSearchInputOptions): UseSearchInputReturn {
93 const { columns: terminalColumns } = useTerminalSize()
94 const effectiveColumns = columns ?? terminalColumns
95 const [query, setQueryState] = useState(initialQuery)
96 const [cursorOffset, setCursorOffset] = useState(initialQuery.length)
97
98 const setQuery = useCallback((q: string) => {
99 setQueryState(q)
100 setCursorOffset(q.length)
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) {

Callers 6

LogSelectorFunction · 0.50
PermissionRuleListFunction · 0.50
ConfigFunction · 0.50
ManagePluginsFunction · 0.50
DiscoverPluginsFunction · 0.50
TranscriptSearchBarFunction · 0.50

Calls 3

useInputFunction · 0.90
useTerminalSizeFunction · 0.85
handleKeyDownFunction · 0.70

Tested by

no test coverage detected