fix(tui): address code review findings

Medium fixes:
- textInput.tsx: prevent silent data loss when async paste resolves
  after user types — fall back to raw text insert at current cursor
  instead of dropping the content entirely
- useComposerState.ts: tighten looksLikeDroppedPath to require a
  second '/' or '.' for bare absolute paths, avoiding unnecessary
  RPC round-trips for pasted text like /api or /help
- useComposerState.ts: add cross-reference comment linking to the
  canonical _detect_file_drop() in cli.py
- osc52.ts: add 500ms timeout via Promise.race so terminals that
  do not support OSC52 clipboard queries cannot hang paste

Low fixes:
- terminalSetup.ts: export isRemoteShellSession and reuse in
  terminalParity.ts and useComposerState.ts (was inlined 3 times)
- useComposerState.ts: extract insertAtCursor helper, replacing 3
  copies of the lead/tail spacing logic
- useComposerState.ts: remove redundant gw from handleTextPaste
  useCallback dependency array
- terminalSetup.test.ts: add EACCES (read-only keybindings.json)
  and unterminated block comment test coverage
This commit is contained in:
kshitijk4poor 2026-04-21 20:29:20 +05:30 committed by kshitij
parent bc9927dc50
commit c9e8d82ef4
7 changed files with 95 additions and 42 deletions

View file

@ -438,10 +438,18 @@ export function TextInput({
const h = cbPaste.current?.(e)
if (isPasteResultPromise(h)) {
const fallbackText = e.text
void h
.then(result => {
if (result && editVersionRef.current === startVersion) {
commit(result.value, result.cursor)
} else if (result && fallbackText && PRINTABLE.test(fallbackText)) {
// User typed while async paste was in-flight — fall back to raw text insert
// so the pasted content is not silently lost.
const cur = curRef.current
const v = vRef.current
commit(v.slice(0, cur) + fallbackText + v.slice(cur), cur + fallbackText.length)
}
})
.catch(() => {})