From 057a8f6f1b29325e382a51344db5e610ff5f0a7e Mon Sep 17 00:00:00 2001 From: Pete Blois Date: Mon, 9 Nov 2020 11:00:44 -0800 Subject: [PATCH 1/8] Incorporate shadowRoot in focus calculation. This adds a call to getRootNode to get either the Document or the ShadowRoot to use when calculating whether the textarea has focus. getRootNode is guarded for older browser compatibility (IE). --- src/browser/services/CoreBrowserService.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/browser/services/CoreBrowserService.ts b/src/browser/services/CoreBrowserService.ts index 985253d9..4eabc895 100644 --- a/src/browser/services/CoreBrowserService.ts +++ b/src/browser/services/CoreBrowserService.ts @@ -14,6 +14,7 @@ export class CoreBrowserService implements ICoreBrowserService { } public get isFocused(): boolean { - return document.activeElement === this._textarea && document.hasFocus(); + const docOrShadowRoot = this._textarea.getRootNode ? this._textarea.getRootNode() as Document | ShadowRoot : document; + return docOrShadowRoot.activeElement === this._textarea && document.hasFocus(); } } From 9616851e52ca4448166099a2620c82162bdb7502 Mon Sep 17 00:00:00 2001 From: Katerina Koukiou Date: Tue, 10 Nov 2020 16:36:59 +0100 Subject: [PATCH 2/8] Fix a11y violation because of using role='listitem' without role='list' parent --- src/browser/AccessibilityManager.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/browser/AccessibilityManager.ts b/src/browser/AccessibilityManager.ts index 0f25ea08..c55aaad9 100644 --- a/src/browser/AccessibilityManager.ts +++ b/src/browser/AccessibilityManager.ts @@ -56,6 +56,7 @@ export class AccessibilityManager extends Disposable { this._accessibilityTreeRoot.classList.add('xterm-accessibility'); this._rowContainer = document.createElement('div'); + this._rowContainer.setAttribute('role', 'list'); this._rowContainer.classList.add('xterm-accessibility-tree'); this._rowElements = []; for (let i = 0; i < this._terminal.rows; i++) { From af2f744186855209ee35e727c25023544c501704 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Wed, 11 Nov 2020 09:43:17 -0800 Subject: [PATCH 3/8] use Array.includes --- src/common/Platform.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/common/Platform.ts b/src/common/Platform.ts index ae23c02e..8838ca9d 100644 --- a/src/common/Platform.ts +++ b/src/common/Platform.ts @@ -23,17 +23,8 @@ export const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent); // Find the users platform. We use this to interpret the meta key // and ISO third level shifts. // http://stackoverflow.com/q/19877924/577598 -export const isMac = contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform); +export const isMac = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'].includes(platform); export const isIpad = platform === 'iPad'; export const isIphone = platform === 'iPhone'; -export const isWindows = contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform); +export const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].includes(platform); export const isLinux = platform.indexOf('Linux') >= 0; - -/** - * Return if the given array contains the given element - * @param arr The array to search for the given element. - * @param el The element to look for into the array - */ -function contains(arr: any[], el: any): boolean { - return arr.indexOf(el) >= 0; -} From 04e2bdd6ec6a80846322464243067bde2d0fc240 Mon Sep 17 00:00:00 2001 From: Tony Mottaz Date: Fri, 20 Nov 2020 19:50:03 -0600 Subject: [PATCH 4/8] Make alt+click behavior configurable --- src/browser/services/SelectionService.ts | 2 +- src/common/services/OptionsService.ts | 2 +- src/common/services/Services.ts | 1 + typings/xterm.d.ts | 5 +++++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/browser/services/SelectionService.ts b/src/browser/services/SelectionService.ts index 81e72087..6caca2a0 100644 --- a/src/browser/services/SelectionService.ts +++ b/src/browser/services/SelectionService.ts @@ -676,7 +676,7 @@ export class SelectionService extends Disposable implements ISelectionService { this._bufferService.rows, false ); - if (coordinates && coordinates[0] !== undefined && coordinates[1] !== undefined) { + if (this._optionsService.getOption('altClickMovesCursor') && coordinates && coordinates[0] !== undefined && coordinates[1] !== undefined) { const sequence = moveToCellSequence(coordinates[0] - 1, coordinates[1] - 1, this._bufferService, this._coreService.decPrivateModes.applicationCursorKeys); this._coreService.triggerDataEvent(sequence, true); } diff --git a/src/common/services/OptionsService.ts b/src/common/services/OptionsService.ts index 6c43c303..b7a1c58e 100644 --- a/src/common/services/OptionsService.ts +++ b/src/common/services/OptionsService.ts @@ -50,7 +50,7 @@ export const DEFAULT_OPTIONS: ITerminalOptions = Object.freeze({ windowOptions: {}, windowsMode: false, wordSeparator: ' ()[]{}\',"`', - + altClickMovesCursor: true, convertEol: false, termName: 'xterm', cancelEvents: false diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index 0ea7a308..9845fdc4 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -220,6 +220,7 @@ export interface IPartialTerminalOptions { export interface ITerminalOptions { allowProposedApi: boolean; allowTransparency: boolean; + altClickMovesCursor: boolean; bellSound: string; bellStyle: 'none' | 'sound' /* | 'visual' | 'both' */; cols: number; diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index b5a736a7..795dd2c6 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -44,6 +44,11 @@ declare module 'xterm' { */ allowTransparency?: boolean; + /** + * If enabled, alt + click will move the prompt cursor to position underneath the mouse. + */ + altClickMovesCursor?: boolean; + /** * A data uri of the sound to use for the bell when `bellStyle = 'sound'`. */ From f68ff2a455f3618d638baf25503c8c932e291506 Mon Sep 17 00:00:00 2001 From: Tony Mottaz Date: Sun, 22 Nov 2020 10:00:02 -0600 Subject: [PATCH 5/8] Check for alt+click option sooner --- src/browser/services/SelectionService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/browser/services/SelectionService.ts b/src/browser/services/SelectionService.ts index 6caca2a0..a3d8d12c 100644 --- a/src/browser/services/SelectionService.ts +++ b/src/browser/services/SelectionService.ts @@ -667,7 +667,7 @@ export class SelectionService extends Disposable implements ISelectionService { this._removeMouseDownListeners(); - if (this.selectionText.length <= 1 && timeElapsed < ALT_CLICK_MOVE_CURSOR_TIME && event.altKey) { + if (this.selectionText.length <= 1 && timeElapsed < ALT_CLICK_MOVE_CURSOR_TIME && event.altKey && this._optionsService.getOption('altClickMovesCursor')) { if (this._bufferService.buffer.ybase === this._bufferService.buffer.ydisp) { const coordinates = this._mouseService.getCoords( event, @@ -676,7 +676,7 @@ export class SelectionService extends Disposable implements ISelectionService { this._bufferService.rows, false ); - if (this._optionsService.getOption('altClickMovesCursor') && coordinates && coordinates[0] !== undefined && coordinates[1] !== undefined) { + if (coordinates && coordinates[0] !== undefined && coordinates[1] !== undefined) { const sequence = moveToCellSequence(coordinates[0] - 1, coordinates[1] - 1, this._bufferService, this._coreService.decPrivateModes.applicationCursorKeys); this._coreService.triggerDataEvent(sequence, true); } From 78ddb9febaac00bddd5c0953c15a6534d619a833 Mon Sep 17 00:00:00 2001 From: Tony Mottaz Date: Sun, 22 Nov 2020 10:00:41 -0600 Subject: [PATCH 6/8] Add 'altClickMovesCursor' option to getOption/setOption in Terminal --- src/browser/public/Terminal.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/browser/public/Terminal.ts b/src/browser/public/Terminal.ts index 33aa9024..64c65fe9 100644 --- a/src/browser/public/Terminal.ts +++ b/src/browser/public/Terminal.ts @@ -170,7 +170,7 @@ export class Terminal implements ITerminalApi { this._core.paste(data); } public getOption(key: 'bellSound' | 'bellStyle' | 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string; - public getOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'visualBell'): boolean; + public getOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'visualBell'): boolean; public getOption(key: 'cols' | 'fontSize' | 'letterSpacing' | 'lineHeight' | 'rows' | 'tabStopWidth' | 'scrollback'): number; public getOption(key: 'fontWeight' | 'fontWeightBold'): FontWeight; public getOption(key: string): any; @@ -182,7 +182,7 @@ export class Terminal implements ITerminalApi { public setOption(key: 'logLevel', value: 'debug' | 'info' | 'warn' | 'error' | 'off'): void; public setOption(key: 'bellStyle', value: 'none' | 'visual' | 'sound' | 'both'): void; public setOption(key: 'cursorStyle', value: 'block' | 'underline' | 'bar'): void; - public setOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'visualBell', value: boolean): void; + public setOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'visualBell', value: boolean): void; public setOption(key: 'fontSize' | 'letterSpacing' | 'lineHeight' | 'tabStopWidth' | 'scrollback', value: number): void; public setOption(key: 'theme', value: ITheme): void; public setOption(key: 'cols' | 'rows', value: number): void; From 88f0b91056adc444bd1197d42c2bfdc112d4c1b2 Mon Sep 17 00:00:00 2001 From: Tony Mottaz Date: Sun, 22 Nov 2020 10:01:02 -0600 Subject: [PATCH 7/8] add altClickMovesCursor option to Services type --- src/common/services/Services.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index 9845fdc4..c733e73e 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -184,6 +184,7 @@ export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'off'; export type RendererType = 'dom' | 'canvas'; export interface IPartialTerminalOptions { + altClickMovesCursor?: boolean; allowTransparency?: boolean; bellSound?: string; bellStyle?: 'none' | 'sound' /* | 'visual' | 'both' */; From e3cccd619b541bf7ce88e65a9c3d10a7fca0af58 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 24 Nov 2020 09:03:59 -0800 Subject: [PATCH 8/8] Update typings/xterm.d.ts --- typings/xterm.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 795dd2c6..d860ddfa 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -45,7 +45,8 @@ declare module 'xterm' { allowTransparency?: boolean; /** - * If enabled, alt + click will move the prompt cursor to position underneath the mouse. + * If enabled, alt + click will move the prompt cursor to position + * underneath the mouse. The default is true. */ altClickMovesCursor?: boolean;