Skip to content

harden linux middle-click primary-selection paste - #18078

Merged
kevinushey merged 1 commit into
mainfrom
bugfix/middle-click-paste-hardening
Jun 27, 2026
Merged

kevinushey merged 1 commit into
mainfrom
bugfix/middle-click-paste-hardening

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Summary

Hardens Linux Desktop middle-click (X11 primary selection) paste in the editor and console, addressing long-standing gaps in how the tracked selection is synced and consumed.

Background: on Linux Desktop, RStudio mirrors a focused Ace editor's selection into the X11 primary selection (clipboard.writeText(sel, 'selection')) and, on a middle-click paste, reads it back instead of the normal clipboard. The sync was driven solely by a 100ms debounce timer, and the paste path used whatever the tracked selection returned even when empty.

Changes

  • Flush on mouse-up. The selection is now pushed to the primary selection immediately on mouse release, rather than waiting up to 100ms for the debounce timer. This closes the race where a quick select-then-middle-click-paste fired before the timer. The timer is retained for keyboard/programmatic selection changes; the new path is a no-op when no selection is pending.
  • Empty-selection fallback. On a middle-click paste, if the tracked global mouse selection is empty (debounce race, or a selection sourced from a non-Ace widget), we now fall back to the text the paste event already carried -- which holds the primary-selection content -- instead of pasting nothing.
  • Minor: use contentEquals instead of string identity in the middle-click event-type check, for consistency with the surrounding predicate.

Not addressed here

  • The global MiddleClickAutoscroll Blink switch (added in fix slow data viewer when the summary panel is shown #17812 for the data viewer) may compete with middle-click paste in the scrollable editor/console. That needs a Linux X11 repro before changing, since it would risk regressing data-viewer panning. Tracked separately.
  • Wayland primary-selection behavior is unchanged (Electron/compositor dependent).

Testing

  • cd src/gwt && ant javac succeeds.
  • Manual verification on Linux Desktop still required (no automated coverage; see discussion on the difficulty of an E2E test for middle-click paste).

Addresses #1667.

flush the tracked selection to the x11 primary selection on mouse-up
instead of relying solely on the 100ms debounce timer, so a quick
select-then-middle-click-paste no longer races the timer.

on a middle-click paste, fall back to the paste event's clipboard text
when the tracked global mouse selection is empty (debounce race, or a
selection sourced from a non-ace widget).

also use contentEquals instead of string identity in the middle-click
event-type check for consistency with the surrounding predicate.

Addresses #1667.
@kevinushey kevinushey added this to the 2026.07 (Pacific Dogwood) milestone Jun 26, 2026
@kevinushey

Copy link
Copy Markdown
Collaborator Author

Manual verification (Linux Desktop only)

This change is gated to Linux Desktop (X11 primary selection), so it can only be verified there. No automated coverage -- a true middle-click-paste E2E is too environment-fragile (depends on the display server and on Chromium delivering a native paste from a synthesized middle-click).

Suggested steps on a Linux X11 desktop build:

  1. Editor -> console (basic): select some text in a source editor, then middle-click in the console input. The selected text should paste.
  2. Fast select-then-paste (the flush-on-mouse-up fix): quickly select text and middle-click-paste into another pane within ~100ms. Previously this could paste nothing; it should now paste the selection.
  3. Console -> editor: select text in the console input, middle-click-paste into a source editor.
  4. Empty-selection fallback: select text in a non-Ace region (e.g. a help topic or rendered output), then middle-click into the editor/console; the primary-selection text should still paste rather than nothing.
  5. No regression to Ctrl+V: confirm normal clipboard paste (Ctrl+V) still works in editor and console.

Note: under Wayland, behavior is Electron/compositor dependent and out of scope for this change. The interaction with the global MiddleClickAutoscroll switch (#17812) is tracked separately.

@github-actions

Copy link
Copy Markdown

🍎 macOS Desktop E2E · ARM64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
412 0 8 0
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · macos-26 ARM64 · commit f318ca5b92ddf96fd936ba1bd6bab29f5bfd80c7 · Run #200

@github-actions

Copy link
Copy Markdown

🪟 Windows Desktop E2E · Server 2025 x64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
411 0 11 0
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · Windows Server 2025 x64 · commit f318ca5b92ddf96fd936ba1bd6bab29f5bfd80c7 · Run #200

@kevinushey
kevinushey merged commit 30cbfe9 into main Jun 27, 2026
15 checks passed
@kevinushey
kevinushey deleted the bugfix/middle-click-paste-hardening branch June 27, 2026 01:48
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