Skip to content

Compose a pasted CR/LF instead of submitting on it - #347

Merged
TheGreatAxios merged 2 commits into
release/tui-bugfixesfrom
cl-5541-pasting-into-the-prompt-is-broken
Aug 7, 2026
Merged

Compose a pasted CR/LF instead of submitting on it#347
TheGreatAxios merged 2 commits into
release/tui-bugfixesfrom
cl-5541-pasting-into-the-prompt-is-broken

Conversation

@TheGreatAxios

@TheGreatAxios TheGreatAxios commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • A terminal without bracketed-paste negotiation delivers a multi-line paste as raw keystrokes, so a bare CR mid-paste hit the same "return" binding that sends the message, splitting one pasted message into several
  • An unmodified Enter is treated as paste-carried (composed as a newline) only when it lands in a keystroke burst immediately after a plain character, and only for a session that has never once fired a real bracketed-paste event -- the first real paste proves the terminal negotiates DEC 2004 and retires the fallback for good
  • A CRLF pair collapses to a single newline; a deliberate Ctrl+J-then-Enter still sends, since Ctrl+J is never a "printable character" for the burst check

Verification

  • bun run typecheck, bun run build, and bun test all pass (4320 pass, 0 fail) after rebasing onto release/tui-bugfixes
  • Drove the real key path by running the built CLI in a pty: bracketed paste (ESC[200~...ESC[201~), Ctrl+V/Ctrl+P clipboard image attach, and a raw un-bracketed CRLF paste were all observed directly in the rendered frames
  • Before the fix, writing line one\r\nline two\r\nline three without bracketed-paste markers sent "line one" and "line two" as separate messages; after the fix it composes into one three-line prompt, matching bracketed-paste behavior
  • Added a test proving the fallback retires after one real paste event, so a fast keystroke burst on a terminal that has already negotiated DEC 2004 never risks a false-positive newline-for-Enter
  • Bracketed paste, multi-line/CRLF paste inside brackets, chunked large paste, and Ctrl+V/Ctrl+P clipboard image attach (including under negotiated Kitty keyboard protocol) were re-verified unaffected
  • The fallback bookkeeping lives in the key handler's own closure, not on AppShell -- no new permanent shell state

Closes CL-5541

@linear-code

linear-code Bot commented Aug 7, 2026

Copy link
Copy Markdown

CL-5541

@TheGreatAxios
TheGreatAxios changed the base branch from main to release/tui-bugfixes August 7, 2026 04:20
@TheGreatAxios
TheGreatAxios force-pushed the cl-5541-pasting-into-the-prompt-is-broken branch from 5354401 to f22ee89 Compare August 7, 2026 04:36
A terminal that never negotiates bracketed paste (DEC 2004) delivers a
multi-line paste as ordinary keystrokes, carriage returns included, and
a bare CR is the same "return" that sends the message. Pasting three
lines was sending three separate messages instead of composing one.

An unmodified Enter that lands in a keystroke burst right after a plain
character is paste-carried, not a deliberate submit, so it now becomes
a newline; a CRLF pair collapses to one newline instead of two. A real
Ctrl+J-then-Enter (insert a line, then send) still sends, since Ctrl+J
never counts as "a printable character" preceding it.
The guard from the previous commit ran on every keystroke regardless
of whether the terminal actually needed it. A terminal proves it
negotiates DEC 2004 the first time it fires a real paste event -- from
then on every paste arrives as that one event, never as raw
keystrokes, so the fallback has nothing left to guard against. Retire
it for the session once that happens instead of re-running it forever;
terminals that never send a paste event keep the guard, since they've
never shown they can do better.

Also moves the bookkeeping (last keypress time, whether it was
printable, whether to swallow the next linefeed) off AppShell and into
the key handler's own closure -- nothing outside that handler read it.
@TheGreatAxios
TheGreatAxios force-pushed the cl-5541-pasting-into-the-prompt-is-broken branch from f22ee89 to 069df2e Compare August 7, 2026 04:58
@TheGreatAxios
TheGreatAxios merged commit f5029b9 into release/tui-bugfixes Aug 7, 2026
2 checks passed
@TheGreatAxios
TheGreatAxios deleted the cl-5541-pasting-into-the-prompt-is-broken branch August 7, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant