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

Function onInput

src/hooks/useTextInput.ts:431–501  ·  view source on GitHub ↗
(input: string, key: Key)

Source from the content-addressed store, hash-verified

429 }
430
431 function onInput(input: string, key: Key): void {
432 // Note: Image paste shortcut (chat:imagePaste) is handled via useKeybindings in PromptInput
433
434 // Apply filter if provided
435 const filteredInput = inputFilter ? inputFilter(input, key) : input
436
437 // If the input was filtered out, do nothing
438 if (filteredInput === '' && input !== '') {
439 return
440 }
441
442 // Fix Issue #1853: Filter DEL characters that interfere with backspace in SSH/tmux
443 // In SSH/tmux environments, backspace generates both key events and raw DEL chars
444 if (!key.backspace && !key.delete && input.includes('\x7f')) {
445 const delCount = (input.match(/\x7f/g) || []).length
446
447 // Apply all DEL characters as backspace operations synchronously
448 // Try to delete tokens first, fall back to character backspace
449 let currentCursor = cursor
450 for (let i = 0; i < delCount; i++) {
451 currentCursor =
452 currentCursor.deleteTokenBefore() ?? currentCursor.backspace()
453 }
454
455 // Update state once with the final result
456 if (!cursor.equals(currentCursor)) {
457 if (cursor.text !== currentCursor.text) {
458 onChange(currentCursor.text)
459 }
460 setOffset(currentCursor.offset)
461 }
462 resetKillAccumulation()
463 resetYankState()
464 return
465 }
466
467 // Reset kill accumulation for non-kill keys
468 if (!isKillKey(key, filteredInput)) {
469 resetKillAccumulation()
470 }
471
472 // Reset yank state for non-yank keys (breaks yank-pop chain)
473 if (!isYankKey(key, filteredInput)) {
474 resetYankState()
475 }
476
477 const nextCursor = mapKey(key)(filteredInput)
478 if (nextCursor) {
479 if (!cursor.equals(nextCursor)) {
480 if (cursor.text !== nextCursor.text) {
481 onChange(nextCursor.text)
482 }
483 setOffset(nextCursor.offset)
484 }
485 // SSH-coalesced Enter: on slow links, "o" + Enter can arrive as one
486 // chunk "o\r". parseKeypress only matches s === '\r', so it hit the
487 // default handler above (which stripped the trailing \r). Text with
488 // exactly one trailing \r is coalesced Enter; lone \r is Alt+Enter

Callers 2

BaseTextInputFunction · 0.85
wrappedOnInputFunction · 0.85

Calls 10

resetKillAccumulationFunction · 0.85
resetYankStateFunction · 0.85
mapKeyFunction · 0.85
onSubmitFunction · 0.85
deleteTokenBeforeMethod · 0.80
isKillKeyFunction · 0.70
isYankKeyFunction · 0.70
onChangeFunction · 0.50
backspaceMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected