From 73d20c1d3bc43107236ecd0bcac97550a43875e5 Mon Sep 17 00:00:00 2001 From: Jason Lin Date: Tue, 6 Dec 2022 14:20:29 +1100 Subject: [PATCH 1/2] Add option scrollOnKeypress Note that we also change the existing behavior a bit: CoreService.triggerDataEvent() will not scroll to the bottom unless `wasUserInput` is also true. This actually seems to be the intended behavior according to the doc just above ICoreService.triggerDataEvent(). --- src/browser/Terminal.ts | 2 +- src/common/services/CoreService.ts | 2 +- src/common/services/OptionsService.ts | 1 + src/common/services/Services.ts | 3 ++- typings/xterm.d.ts | 6 ++++++ 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index 3c88b94816..2de0200e00 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -995,7 +995,7 @@ export class Terminal extends CoreTerminal implements ITerminal { const shouldIgnoreComposition = this.browser.isMac && this.options.macOptionIsMeta && event.altKey; if (!shouldIgnoreComposition && !this._compositionHelper!.keydown(event)) { - if (this.buffer.ybase !== this.buffer.ydisp) { + if (this.options.scrollOnKeypress && this.buffer.ybase !== this.buffer.ydisp) { this._bufferService.scrollToBottom(); } return false; diff --git a/src/common/services/CoreService.ts b/src/common/services/CoreService.ts index 9282197b39..101a142ad5 100644 --- a/src/common/services/CoreService.ts +++ b/src/common/services/CoreService.ts @@ -68,7 +68,7 @@ export class CoreService extends Disposable implements ICoreService { // Input is being sent to the terminal, the terminal should focus the prompt. const buffer = this._bufferService.buffer; - if (buffer.ybase !== buffer.ydisp) { + if (wasUserInput && this._optionsService.rawOptions.scrollOnKeypress && buffer.ybase !== buffer.ydisp) { this._scrollToBottom!(); } diff --git a/src/common/services/OptionsService.ts b/src/common/services/OptionsService.ts index 976cdf8dde..d1e4705106 100644 --- a/src/common/services/OptionsService.ts +++ b/src/common/services/OptionsService.ts @@ -28,6 +28,7 @@ export const DEFAULT_OPTIONS: Readonly> = { linkHandler: null, logLevel: 'info', scrollback: 1000, + scrollOnKeypress: true, scrollSensitivity: 1, screenReaderMode: false, smoothScrollDuration: 0, diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index cc3880630a..5f4e692b61 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -87,7 +87,7 @@ export interface ICoreService { * @param data The data that is being emitted. * @param wasFromUser Whether the data originated from the user (as opposed to * resulting from parsing incoming data). When true this will also: - * - Scroll to the bottom of the buffer.s + * - Scroll to the bottom of the buffer if option scrollOnKeypress is true. * - Fire the `onUserInput` event (so selection can be cleared). */ triggerDataEvent(data: string, wasUserInput?: boolean): void; @@ -243,6 +243,7 @@ export interface ITerminalOptions { rows?: number; screenReaderMode?: boolean; scrollback?: number; + scrollOnKeypress?: boolean; scrollSensitivity?: number; smoothScrollDuration?: number; tabStopWidth?: number; diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 926cc6b4a3..2eedaac859 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -193,6 +193,12 @@ declare module 'xterm' { */ scrollback?: number; + /** + * Whether to scroll to the bottom whenever a key is pressed. The default is + * true. + */ + scrollOnKeypress?: boolean; + /** * The scrolling speed multiplier used for adjusting normal scrolling speed. */ From 9e84895141a40a958ec14241a159bbf1e9f2f6a4 Mon Sep 17 00:00:00 2001 From: Jason Lin Date: Wed, 7 Dec 2022 10:12:43 +1100 Subject: [PATCH 2/2] polish --- src/browser/Terminal.ts | 2 +- src/common/services/CoreService.ts | 2 +- src/common/services/OptionsService.ts | 2 +- src/common/services/Services.ts | 6 +++--- typings/xterm.d.ts | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index 2de0200e00..606f3a5342 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -995,7 +995,7 @@ export class Terminal extends CoreTerminal implements ITerminal { const shouldIgnoreComposition = this.browser.isMac && this.options.macOptionIsMeta && event.altKey; if (!shouldIgnoreComposition && !this._compositionHelper!.keydown(event)) { - if (this.options.scrollOnKeypress && this.buffer.ybase !== this.buffer.ydisp) { + if (this.options.scrollOnUserInput && this.buffer.ybase !== this.buffer.ydisp) { this._bufferService.scrollToBottom(); } return false; diff --git a/src/common/services/CoreService.ts b/src/common/services/CoreService.ts index 101a142ad5..321678a13f 100644 --- a/src/common/services/CoreService.ts +++ b/src/common/services/CoreService.ts @@ -68,7 +68,7 @@ export class CoreService extends Disposable implements ICoreService { // Input is being sent to the terminal, the terminal should focus the prompt. const buffer = this._bufferService.buffer; - if (wasUserInput && this._optionsService.rawOptions.scrollOnKeypress && buffer.ybase !== buffer.ydisp) { + if (wasUserInput && this._optionsService.rawOptions.scrollOnUserInput && buffer.ybase !== buffer.ydisp) { this._scrollToBottom!(); } diff --git a/src/common/services/OptionsService.ts b/src/common/services/OptionsService.ts index d1e4705106..9709f2a720 100644 --- a/src/common/services/OptionsService.ts +++ b/src/common/services/OptionsService.ts @@ -28,7 +28,7 @@ export const DEFAULT_OPTIONS: Readonly> = { linkHandler: null, logLevel: 'info', scrollback: 1000, - scrollOnKeypress: true, + scrollOnUserInput: true, scrollSensitivity: 1, screenReaderMode: false, smoothScrollDuration: 0, diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index 5f4e692b61..a5e1c5bcef 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -85,9 +85,9 @@ export interface ICoreService { /** * Triggers the onData event in the public API. * @param data The data that is being emitted. - * @param wasFromUser Whether the data originated from the user (as opposed to + * @param wasUserInput Whether the data originated from the user (as opposed to * resulting from parsing incoming data). When true this will also: - * - Scroll to the bottom of the buffer if option scrollOnKeypress is true. + * - Scroll to the bottom of the buffer if option scrollOnUserInput is true. * - Fire the `onUserInput` event (so selection can be cleared). */ triggerDataEvent(data: string, wasUserInput?: boolean): void; @@ -243,7 +243,7 @@ export interface ITerminalOptions { rows?: number; screenReaderMode?: boolean; scrollback?: number; - scrollOnKeypress?: boolean; + scrollOnUserInput?: boolean; scrollSensitivity?: number; smoothScrollDuration?: number; tabStopWidth?: number; diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 2eedaac859..d5e207fa3b 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -194,10 +194,10 @@ declare module 'xterm' { scrollback?: number; /** - * Whether to scroll to the bottom whenever a key is pressed. The default is - * true. + * Whether to scroll to the bottom whenever there is some user input. The + * default is true. */ - scrollOnKeypress?: boolean; + scrollOnUserInput?: boolean; /** * The scrolling speed multiplier used for adjusting normal scrolling speed.