fix(terminal): respect mouse reporting for right-click press and release (#11935)

* fix(terminal): respect mouse reporting for right-click press and release

* cleanup

---------

Co-authored-by: Eugene <inbox@null.page>
This commit is contained in:
RajkamalandEugene authored and GitHub committed 2026-11-23 23:54:44 +01:00
1 parent 2751199ba1
commit 33cb61cb5b
3 files changed
+32 -9

No files matched your search

@@ -665,6 +665,7 @@ export class BaseTerminalTabComponent<P extends BaseTerminalProfile> extends Bas
}
private rightMouseDownTime = 0
private rightClickLeftToApp = false
protected async handleRightMouseDown (event: MouseEvent): Promise<void> {
event.preventDefault()
@@ -729,7 +730,8 @@ export class BaseTerminalTabComponent<P extends BaseTerminalProfile> extends Bas
this.termContainerSubscriptions.subscribe(this.focused$, () => this.frontend && (this.frontend.enableResizing = true))
this.termContainerSubscriptions.subscribe(this.blurred$, () => this.frontend && (this.frontend.enableResizing = false))
this.termContainerSubscriptions.subscribe(this.frontend.mouseEvent$, event => {
const frontend = this.frontend
this.termContainerSubscriptions.subscribe(frontend.mouseEvent$, event => {
if (event.type === 'mousedown') {
if (event.which === 1) {
this.multifocus.cancel()
@@ -743,13 +745,21 @@ export class BaseTerminalTabComponent<P extends BaseTerminalProfile> extends Bas
return
}
if (event.which === 3 || event.which === 1 && event.ctrlKey) {
this.handleRightMouseDown(event)
// Right-click is off and the app tracks the mouse: xterm has reported
// the press and listens for the release on `document`, so leave both
// events alone. Decided on the press, as the app may change modes in response.
this.rightClickLeftToApp = this.config.store.terminal.rightClick === 'off' && frontend.isMouseTrackingActive()
if (!this.rightClickLeftToApp) {
this.handleRightMouseDown(event)
}
return
}
}
if (event.type === 'mouseup') {
if (event.which === 3 || event.which === 1 && event.ctrlKey) {
this.handleRightMouseUp(event)
if (!this.rightClickLeftToApp) {
this.handleRightMouseUp(event)
}
return
}
}
+5
View File
@@ -94,6 +94,11 @@ export abstract class Frontend {
abstract supportsBracketedPaste (): boolean
abstract isAlternateScreenActive (): boolean
/** Whether the running application has asked for mouse events */
isMouseTrackingActive (): boolean {
return false
}
/**
* Reset terminal modes (mouse tracking, bracketed paste, cursor visibility, etc.)
* Called on session reconnection to prevent stale modes from leaking
+14 -6
View File
@@ -497,12 +497,16 @@ export class XTermFrontend extends Frontend {
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)
// Tabby handles right-click itself (menu/paste/copy), so don't let
// xterm also report it to apps with mouse tracking enabled - some of
// them paste on right-click, doubling the paste.
// With right-click turned off, the click is the app's instead.
const e = event as MouseEvent
const rightClick = e.button === 2 || e.button === 0 && e.ctrlKey
if (rightClick && this.isMouseTrackingActive() && this.configService.store.terminal.rightClick !== 'off') {
// "immediate" also skips our own bubble listener when the host itself is the target
event.stopImmediatePropagation()
this.mouseEvent.next(e)
}
},
mousewheel: event => this.mouseEvent.next(event as MouseEvent),
@@ -834,6 +838,10 @@ export class XTermFrontend extends Frontend {
return this.xterm.modes.bracketedPasteMode
}
isMouseTrackingActive (): boolean {
return this.xterm.modes.mouseTrackingMode !== 'none'
}
isAlternateScreenActive (): boolean {
return this.xterm.buffer.active.type === 'alternate'
}