Skip to content

fix: suppress right-click paste after failed drag-select with mouse reporting#90

Merged
InbarR merged 1 commit into
InbarR:mainfrom
eladavraham:fix/rightclick-paste-mouse-reporting
May 4, 2026
Merged

fix: suppress right-click paste after failed drag-select with mouse reporting#90
InbarR merged 1 commit into
InbarR:mainfrom
eladavraham:fix/rightclick-paste-mouse-reporting

Conversation

@eladavraham
Copy link
Copy Markdown
Contributor

Problem

When a TUI app (Claude Code, Copilot CLI, vim, etc.) enables mouse reporting, drag-selecting text is consumed by the pty xterm never creates a DOM selection. Right-clicking then triggers paste instead of copy, because \hasSelection()\ returns false.

Fix

Track left-button drag attempts. When a drag occurred with mouse tracking active and no xterm selection resulted, suppress the auto-paste on the subsequent right-click. The flag auto-expires after 3s.

This is narrower than blocking all paste when mouse reporting is on (which would break PSReadLine's click-to-position since it enables ?1003h).

  • Users can always Ctrl+V to paste explicitly
  • Normal right-click paste (no mouse reporting or no preceding drag) is unaffected

Test

Added
ightclick-paste-mouse-reporting-text.spec.ts\ with two cases:

  1. Drag + right-click with mouse reporting ON no paste
  2. Right-click in normal shell paste works

…eporting

When a TUI app enables mouse reporting, xterm forwards drag events to the
pty as SGR mouse sequences instead of creating a DOM selection. The user
thinks they selected text, but hasSelection() returns false  causing the
right-click handler to paste clipboard content into the terminal.

Fix: track left-button drag attempts. When a drag occurred with mouse
tracking active and no xterm selection resulted, set a short-lived flag
(recentDragWithoutSelection) that suppresses the paste on the subsequent
right-click. This is narrower than blocking all paste when mouse reporting
is on (which breaks PSReadLine's click-to-position since it enables ?1003h).

The flag auto-expires after 3s so intentional TUI mouse interactions don't
permanently disable paste. Users can always Ctrl+V to paste explicitly.

Applied to both TerminalPanel and DetachedApp.
Added e2e tests verifying both the fix and no-regression.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@InbarR InbarR marked this pull request as ready for review May 4, 2026 20:17
@InbarR InbarR merged commit b3485c1 into InbarR:main May 4, 2026
@InbarR
Copy link
Copy Markdown
Owner

InbarR commented May 4, 2026

Merged in b3485c1 - confirmed working in dev tmax against Copilot CLI (drag in the TUI, right-click after, clipboard text no longer leaks into the prompt). Thanks @eladavraham!

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