fix: prevent Windows paste from submitting existing CLI input#357
Conversation
Prevent plain Enter/Tab at the start of a Windows paste burst from being forwarded immediately, which could submit existing CLI input before pasted content arrives. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
Fixes an input-handling edge case in the Windows client loop where a paste that begins with a plain newline/tab could submit existing CLI input before the rest of the paste arrives, by buffering leading Enter/Tab into the paste-pending buffer when paste detection is enabled.
Changes:
- Buffer leading plain
Enter/Tabintopaste_pendwhen paste-detection is enabled (Windows) to avoid prematuresend-keysubmission. - Add
should_buffer_leading_paste_control(...)helper and startpaste_pend_startwhen buffering begins. - Add Windows-only unit tests validating the helper behavior for Enter/Tab + modifier/detection combinations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/client.rs | Buffers leading plain Enter/Tab as part of paste detection and introduces a helper to centralize the decision logic. |
| tests-rs/test_client.rs | Adds Windows-only tests covering buffering decisions for leading Enter/Tab under paste detection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ewline fix Adds reproduction and verification scripts that exercise PR #357 end to end on Windows: * repro_pr357_paste_submit.ps1 reproduces the premature submit (pasting clipboard that starts with a newline used to submit the pending CLI input). * brackpaste_child.cs is a reader that enables bracketed paste (ESC[?2004h) like Copilot CLI and Claude Code do. * verify_pr357_bracketed.ps1 proves the leading newline is now delivered INSIDE the bracketed paste (ESC[200~ ... 0x0D ... ESC[201~) with no premature standalone Enter before the opener. Verified against the merged fix: 3/3 bracketed-paste checks pass and the 10 helper unit tests pass.
|
Thanks for this @tarikguney. I reproduced the underlying problem on Windows and verified the fix end to end, then merged it (commit a2f4718). Reproduced the bug (before this PR) In a psmux pane I typed an invalid partial command and left the cursor on the line without pressing Enter, then pasted clipboard content that began with a newline. The leading pasted newline was forwarded as an immediate Enter, so the partial command was submitted early and the shell raised a "not recognized" error before the rest of the paste arrived. That is exactly the premature submit you described for the Copilot and Claude Code input. Verified the fix
The change is nicely scoped: leading plain Enter or Tab is buffered into the paste only when paste detection is on, modified Enter and Tab are untouched, and behavior is unchanged when paste detection is off. I added tangible repro and verification scripts in commit 0741c87 so this stays covered going forward. Nice work, merged. |
Summary
When a Windows paste started with a newline/tab,
psmuxcould send Enter/Tab immediately before the rest of the paste arrived. That submitted the current Copilot CLI input unexpectedly. This change buffers leading plain Enter/Tab as part of paste detection so the whole clipboard payload is delivered together.Details
In the Windows client input loop (
src/client.rs),KeyCode::EnterandKeyCode::Tabwere only appended topaste_pendwhenpaste_pendwas already non-empty. If the first injected key in a Ctrl+V burst was Enter/Tab, the code fell through to immediatesend-key, causing premature command submission in CLI overlays before remaining paste bytes were processed.This PR adds
should_buffer_leading_paste_control(...)and uses it in Enter/Tab handling to buffer leading plain Enter/Tab whenpaste-detectionis enabled. It also startspaste_pend_startwhen buffering begins. Behavior remains unchanged for modified Enter/Tab and whenpaste-detectionis disabled.Tests were added in
tests-rs/test_client.rsto verify:Test Plan
cargo test --test test_client) and verify new helper tests passMade with Cursor