diff --git a/src/browser/CoreBrowserTerminal.ts b/src/browser/CoreBrowserTerminal.ts index e66f4c4bf..2942b3952 100644 --- a/src/browser/CoreBrowserTerminal.ts +++ b/src/browser/CoreBrowserTerminal.ts @@ -618,7 +618,7 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal { this._register(addDisposableListener(this.element, 'mousedown', (e: MouseEvent) => this._selectionService!.handleMouseDown(e))); // apply mouse event classes set by escape codes before terminal was attached - if (this.mouseStateService.areMouseEventsActive && !this.options.altClickForMouseEvents) { + if (this.mouseStateService.areMouseEventsActive && !this.options.mouseEventsRequireAlt) { this._selectionService.disable(); this.element.classList.add('enable-mouse-events'); } else { diff --git a/src/browser/services/MouseService.ts b/src/browser/services/MouseService.ts index c6e581458..20f5602e6 100644 --- a/src/browser/services/MouseService.ts +++ b/src/browser/services/MouseService.ts @@ -154,7 +154,7 @@ export class MouseService implements IMouseService { } if (but !== CoreMouseButton.WHEEL - && this._optionsService.rawOptions.altClickForMouseEvents + && this._optionsService.rawOptions.mouseEventsRequireAlt && this._mouseStateService.areMouseEventsActive && !ev.altKey) { return false; @@ -368,7 +368,7 @@ export class MouseService implements IMouseService { if (this._optionsService.rawOptions.logLevel === 'debug') { this._logService.debug('Binding to mouse events:', this._explainEvents(events)); } - if (this._optionsService.rawOptions.altClickForMouseEvents) { + if (this._optionsService.rawOptions.mouseEventsRequireAlt) { this._selectionService.enable(); } else { element.classList.add('enable-mouse-events'); diff --git a/src/browser/services/SelectionService.test.ts b/src/browser/services/SelectionService.test.ts index 4677626ab..04d691d40 100644 --- a/src/browser/services/SelectionService.test.ts +++ b/src/browser/services/SelectionService.test.ts @@ -504,15 +504,15 @@ describe('SelectionService', () => { }); describe('shouldForceSelection', () => { - it('should force selection without alt when altClickForMouseEvents is enabled', () => { - optionsService.options.altClickForMouseEvents = true; + it('should force selection without alt when mouseEventsRequireAlt is enabled', () => { + optionsService.options.mouseEventsRequireAlt = true; mouseStateService.areMouseEventsActive = true; assert.isTrue(selectionService.shouldForceSelection({ altKey: false } as MouseEvent)); assert.isFalse(selectionService.shouldForceSelection({ altKey: true } as MouseEvent)); }); it('should take precedence over macOptionClickForcesSelection', () => { - optionsService.options.altClickForMouseEvents = true; + optionsService.options.mouseEventsRequireAlt = true; optionsService.options.macOptionClickForcesSelection = true; mouseStateService.areMouseEventsActive = true; assert.isFalse(selectionService.shouldForceSelection({ altKey: true } as MouseEvent)); diff --git a/src/browser/services/SelectionService.ts b/src/browser/services/SelectionService.ts index e10d45c54..605fa7a0e 100644 --- a/src/browser/services/SelectionService.ts +++ b/src/browser/services/SelectionService.ts @@ -435,7 +435,7 @@ export class SelectionService extends Disposable implements ISelectionService { * @param event The mouse event. */ public shouldForceSelection(event: MouseEvent): boolean { - if (this._optionsService.rawOptions.altClickForMouseEvents && this._mouseStateService.areMouseEventsActive) { + if (this._optionsService.rawOptions.mouseEventsRequireAlt && this._mouseStateService.areMouseEventsActive) { return !event.altKey; } @@ -463,7 +463,7 @@ export class SelectionService extends Disposable implements ISelectionService { return; } - if (this._optionsService.rawOptions.altClickForMouseEvents && this._mouseStateService.areMouseEventsActive && event.altKey) { + if (this._optionsService.rawOptions.mouseEventsRequireAlt && this._mouseStateService.areMouseEventsActive && event.altKey) { return; } @@ -605,7 +605,7 @@ export class SelectionService extends Disposable implements ISelectionService { * @param event the mouse or keyboard event */ public shouldColumnSelect(event: KeyboardEvent | MouseEvent): boolean { - if (this._optionsService.rawOptions.altClickForMouseEvents && this._mouseStateService.areMouseEventsActive) { + if (this._optionsService.rawOptions.mouseEventsRequireAlt && this._mouseStateService.areMouseEventsActive) { return false; } return event.altKey && !(Browser.isMac && this._optionsService.rawOptions.macOptionClickForcesSelection); diff --git a/src/common/services/OptionsService.ts b/src/common/services/OptionsService.ts index 99ed8435a..8527d2ea0 100644 --- a/src/common/services/OptionsService.ts +++ b/src/common/services/OptionsService.ts @@ -41,6 +41,7 @@ export const DEFAULT_OPTIONS: Readonly> = { macOptionIsMeta: false, macOptionClickForcesSelection: false, minimumContrastRatio: 1, + mouseEventsRequireAlt: false, disableStdin: false, allowProposedApi: false, allowTransparency: false, @@ -52,7 +53,6 @@ export const DEFAULT_OPTIONS: Readonly> = { windowOptions: {}, windowsPty: {}, wordSeparator: ' ()[]{}\',"`', - altClickForMouseEvents: false, altClickMovesCursor: true, convertEol: false, termName: 'xterm', diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index d63197585..fa1c4412f 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -209,7 +209,6 @@ export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'off'; export interface ITerminalOptions { allowProposedApi?: boolean; allowTransparency?: boolean; - altClickForMouseEvents?: boolean; altClickMovesCursor?: boolean; cols?: number; convertEol?: boolean; @@ -235,6 +234,7 @@ export interface ITerminalOptions { macOptionIsMeta?: boolean; macOptionClickForcesSelection?: boolean; minimumContrastRatio?: number; + mouseEventsRequireAlt?: boolean; reflowCursorLine?: boolean; rescaleOverlappingGlyphs?: boolean; rightClickSelectsWord?: boolean; diff --git a/typings/xterm-headless.d.ts b/typings/xterm-headless.d.ts index f831fa24f..830087ef6 100644 --- a/typings/xterm-headless.d.ts +++ b/typings/xterm-headless.d.ts @@ -38,16 +38,6 @@ declare module '@xterm/headless' { */ altClickMovesCursor?: boolean; - /** - * When enabled and the terminal is in mouse events mode, mouse click, drag, - * and move events are only sent to the underlying application when the alt - * key is held. Wheel events are not affected. This allows normal text - * selection by default while still supporting application mouse interaction - * and scrolling when holding alt. When enabled, this takes precedence over - * `macOptionClickForcesSelection`. - */ - altClickForMouseEvents?: boolean; - /** * When enabled the cursor will be set to the beginning of the next line * with every new line. This is equivalent to sending '\r\n' for each '\n'. @@ -146,6 +136,16 @@ declare module '@xterm/headless' { */ minimumContrastRatio?: number; + /** + * When enabled and the terminal is in mouse events mode, mouse click, drag, + * and move events are only sent to the underlying application when the alt + * key is held. Wheel events are not affected. This allows normal text + * selection by default while still supporting application mouse interaction + * and scrolling when holding alt. When enabled, this takes precedence over + * `macOptionClickForcesSelection`. + */ + mouseEventsRequireAlt?: boolean; + /** * Whether to reflow the line containing the cursor when the terminal is * resized. Defaults to false, because shells usually handle this diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 0b0450671..f96c316ad 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -45,16 +45,6 @@ declare module '@xterm/xterm' { */ altClickMovesCursor?: boolean; - /** - * When enabled and the terminal is in mouse events mode, mouse click, drag, - * and move events are only sent to the underlying application when the alt - * key is held. Wheel events are not affected. This allows normal text - * selection by default while still supporting application mouse interaction - * and scrolling when holding alt. When enabled, this takes precedence over - * `macOptionClickForcesSelection`. - */ - altClickForMouseEvents?: boolean; - /** * When enabled the cursor will be set to the beginning of the next line * with every new line. This is equivalent to sending `\r\n` for each `\n`. @@ -216,6 +206,16 @@ declare module '@xterm/xterm' { */ minimumContrastRatio?: number; + /** + * When enabled and the terminal is in mouse events mode, mouse click, drag, + * and move events are only sent to the underlying application when the alt + * key is held. Wheel events are not affected. This allows normal text + * selection by default while still supporting application mouse interaction + * and scrolling when holding alt. When enabled, this takes precedence over + * `macOptionClickForcesSelection`. + */ + mouseEventsRequireAlt?: boolean; + /** * Control various quirks features that are either non-standard or standard * in but generally rejected in modern terminals.