fix(terminal): don't forward right-click to mouse-tracking apps (#11744)

Tabby always handles right-click itself (context menu, paste or copy).
When an app enables mouse tracking (e.g. Claude Code, tmux, vim with
mouse=a), xterm also reported the right-click to it, and apps that
paste on right-click inserted the clipboard a second time.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
siparkerandClaude Opus 5.5 authored and GitHub committed 2026-11-23 23:34:11 +01:00
1 parent 6addc79c13
commit 2f77a78a8a
1 file changed
+14
@@ -116,6 +116,7 @@ export class XTermFrontend extends Frontend {
drop: (event: Event) => void
mousedown: (event: Event) => void
mouseup: (event: Event) => void
rightButtonCapture: (event: Event) => void
mousewheel: (event: Event) => void
contextmenu: (event: Event) => void
}
@@ -495,6 +496,15 @@ export class XTermFrontend extends Frontend {
drop: event => this.drop.next(event as DragEvent),
mousedown: event => this.mouseEvent.next(event as MouseEvent),
mouseup: event => this.mouseEvent.next(event as MouseEvent),
rightButtonCapture: event => {
// Tabby always handles right-click itself (menu/paste/copy).
// Don't let xterm also report it to apps with mouse tracking
// enabled - some of them paste on right-click, doubling the paste
if ((event as MouseEvent).button === 2 && this.xterm.modes.mouseTrackingMode !== 'none') {
event.stopPropagation()
this.mouseEvent.next(event as MouseEvent)
}
},
mousewheel: event => this.mouseEvent.next(event as MouseEvent),
contextmenu: event => {
event.preventDefault()
@@ -507,6 +517,8 @@ export class XTermFrontend extends Frontend {
host.addEventListener('drop', this.hostEventHandlers.drop)
host.addEventListener('mousedown', this.hostEventHandlers.mousedown)
host.addEventListener('mouseup', this.hostEventHandlers.mouseup)
host.addEventListener('mousedown', this.hostEventHandlers.rightButtonCapture, true)
host.addEventListener('mouseup', this.hostEventHandlers.rightButtonCapture, true)
host.addEventListener('mousewheel', this.hostEventHandlers.mousewheel)
host.addEventListener('contextmenu', this.hostEventHandlers.contextmenu)
@@ -532,6 +544,8 @@ export class XTermFrontend extends Frontend {
host.removeEventListener('drop', this.hostEventHandlers.drop)
host.removeEventListener('mousedown', this.hostEventHandlers.mousedown)
host.removeEventListener('mouseup', this.hostEventHandlers.mouseup)
host.removeEventListener('mousedown', this.hostEventHandlers.rightButtonCapture, true)
host.removeEventListener('mouseup', this.hostEventHandlers.rightButtonCapture, true)
host.removeEventListener('mousewheel', this.hostEventHandlers.mousewheel)
host.removeEventListener('contextmenu', this.hostEventHandlers.contextmenu)
this.hostEventHandlers = undefined