MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / onInput

Function onInput

source code/hooks/useTextInput.ts:433–503  ·  view source on GitHub ↗
(input: string, key: Key)

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected