Repository navigation
Fix middle click paste over text in terminal on Linux - #338580
Open
Dominik Menke (dmke) wants to merge 1 commit into
Open
Dominik Menke (dmke) wants to merge 1 commit into
Dominik Menke (dmke) wants to merge 1 commit into
Conversation
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Anthony Kim (@anthonykim1)Matched files:
|
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused guard addresses the reported regression while preserving primary-button and quick-pick activation paths, with targeted unit coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes Linux primary-selection paste in the integrated terminal by ignoring non-primary mouse-button link activations before preventing the browser default.
Changes:
- Guards terminal link activation against middle/right mouse buttons.
- Adds coverage verifying only primary-button activation calls
preventDefault(). - Adds the product service test dependency needed by link detection.
| File | Description |
|---|---|
src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkManager.ts |
Skips non-primary link activation before default prevention. |
src/vs/workbench/contrib/terminalContrib/links/test/browser/terminalLinkManager.test.ts |
Tests default-prevention behavior for primary, middle, and secondary buttons. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Author
|
@microsoft-github-policy-service agree |
xterm.js activates links on mouseup of any mouse button. Since the word link detector turns every word into a link, middle clicking on text activated a link, and the activation handler unconditionally called preventDefault() on the mouseup event. Chromium skips pasting the selection clipboard when mouseup is default prevented, so middle click paste only worked on empty terminal space. Ignore link activations from non-primary buttons before calling preventDefault(). Fixes microsoft#157233
Dominik Menke (dmke)
force-pushed
the
fix/terminal-middle-click-paste-157233
branch
from
October 11, 2026 12:35
8c05c6e to
e7fade0
Compare
Author
|
Anthony Kim (@anthonykim1): What's missing to get this merged? |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #157233
Problem
On Linux, middle click pastes the selection clipboard (the X primary selection) into the terminal only when clicking empty terminal space. Clicking on text does nothing. This affects both
terminal.integrated.middleClickBehaviorsettings.Cause
mouseupof any mouse button, not just the primary one (Inserting X selections requires precise mouse positioning xtermjs/xterm.js#4052).TerminalWordLinkDetectormakes every word in the terminal a link, so a middle click on text always lands on a "link".TerminalLinkManager's activation handler callspreventDefault()on the event before it checks the modifier key.mouseupis default prevented. Nopasteevent ever reaches xterm's textarea.I confirmed this in a running Code OSS instance by hooking
Event.prototype.preventDefault. Over text, themouseupwas prevented fromTerminalLink.activate→terminalLinkManager.ts. Over blank space, nothing prevented it.Fix
Ignore link activations from non-primary buttons before calling
preventDefault(). Nothing changes for left-click activation, Ctrl/Alt+click behaviour, or links opened from the quick pick (TerminalLinkQuickPickEventreports button 0).A matching upstream fix for xterm.js is in xtermjs/xterm.js#6194. I've kept the guard here as well, because extension-provided link handlers also go through this code path.
How to test
On Linux:
echo alpha beta gammaa few times.editor.multiCursorModifier) on a URL or file link. It still opens.A unit test in
terminalLinkManager.test.tschecks that only primary-button activations are default prevented.Note
This PR was prepared with the assistance of an AI coding agent (Claude Code). The agent did the investigation (reproducing the bug in a live Code OSS instance and tracing the
preventDefault()call), the fix and the test. I've reviewed the change and tested it locally.