Skip to content

fix: prevent Windows paste from submitting existing CLI input#357

Merged
psmux merged 2 commits into
masterfrom
fix/windows-paste-leading-enter-submit
Jun 8, 2026
Merged

fix: prevent Windows paste from submitting existing CLI input#357
psmux merged 2 commits into
masterfrom
fix/windows-paste-leading-enter-submit

Conversation

@tarikguney

@tarikguney tarikguney commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

When a Windows paste started with a newline/tab, psmux could 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::Enter and KeyCode::Tab were only appended to paste_pend when paste_pend was already non-empty. If the first injected key in a Ctrl+V burst was Enter/Tab, the code fell through to immediate send-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 when paste-detection is enabled. It also starts paste_pend_start when buffering begins. Behavior remains unchanged for modified Enter/Tab and when paste-detection is disabled.

Tests were added in tests-rs/test_client.rs to verify:

  • leading plain Enter buffers when detection is on
  • leading plain Tab buffers when detection is on
  • leading Enter does not buffer when detection is off
  • modified Enter does not buffer

Test Plan

  • Run Windows unit tests (cargo test --test test_client) and verify new helper tests pass
  • Repro manually in Windows: type text in Copilot CLI input, paste content that starts with newline/tab, confirm existing input is not submitted prematurely

Made with Cursor

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/Tab into paste_pend when paste-detection is enabled (Windows) to avoid premature send-key submission.
  • Add should_buffer_leading_paste_control(...) helper and start paste_pend_start when 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.

Comment thread src/client.rs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@psmux psmux merged commit a2f4718 into master Jun 8, 2026
9 checks passed
psmux added a commit that referenced this pull request Jun 8, 2026
…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.
@psmux

psmux commented Jun 8, 2026

Copy link
Copy Markdown
Owner

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

  • All 10 new helper unit tests pass (should_buffer_leading_paste_control and should_zero_latency_flush_paste_pend).
  • With a reader that enables bracketed paste the way Copilot CLI and Claude Code do, the leading newline now arrives INSIDE the bracketed paste payload (ESC[200~ then 0x0D then the text then ESC[201~), with no premature standalone Enter before the opener. So the pending input is no longer submitted early.
  • The full suite stays green with no regressions.

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.

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.

3 participants