MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / useChatKeyboard

Function useChatKeyboard

cli/src/hooks/use-chat-keyboard.ts:289–325  ·  view source on GitHub ↗
({
  state,
  handlers,
  disabled = false,
}: UseChatKeyboardOptions)

Source from the content-addressed store, hash-verified

287 * escape/ctrl-c appropriately.
288 */
289export function useChatKeyboard({
290 state,
291 handlers,
292 disabled = false,
293}: UseChatKeyboardOptions): void {
294 const lastKeyboardActivityRef = useRef<number>(0)
295
296 useKeyboard(
297 useCallback(
298 (key: KeyEvent) => {
299 if (disabled) return
300
301 // Report keyboard activity for activity-aware features (throttled)
302 const now = Date.now()
303 if (now - lastKeyboardActivityRef.current > KEYBOARD_ACTIVITY_THROTTLE_MS) {
304 lastKeyboardActivityRef.current = now
305 reportActivity()
306 }
307
308 markReturnKeySeenForKey(key)
309
310 const action = resolveChatKeyboardAction(key, state)
311 const handled = dispatchAction(action, handlers)
312
313 // Prevent default for handled actions
314 if (
315 handled &&
316 'preventDefault' in key &&
317 typeof key.preventDefault === 'function'
318 ) {
319 key.preventDefault()
320 }
321 },
322 [state, handlers, disabled],
323 ),
324 )
325}

Callers 1

ChatFunction · 0.90

Calls 4

reportActivityFunction · 0.90
markReturnKeySeenForKeyFunction · 0.90
dispatchActionFunction · 0.85

Tested by

no test coverage detected