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().
This commit is contained in:
Jason Lin
2022-12-06 14:29:18 +11:00
parent ad1f2ac2a8
commit 73d20c1d3b
5 changed files with 11 additions and 3 deletions
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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!();
}
+1
View File
@@ -28,6 +28,7 @@ export const DEFAULT_OPTIONS: Readonly<Required<ITerminalOptions>> = {
linkHandler: null,
logLevel: 'info',
scrollback: 1000,
scrollOnKeypress: true,
scrollSensitivity: 1,
screenReaderMode: false,
smoothScrollDuration: 0,
+2 -1
View File
@@ -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;
+6
View File
@@ -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.
*/