From 714513083560612b30f127a36f6a366f2d84977e Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 5 Jan 2021 09:32:09 -0800 Subject: [PATCH] Fix onBufferChange event not working after reset Co-authored-by: Megan Rogge (megan.rogge@microsoft.com) --- src/browser/public/Terminal.ts | 19 +++++++++---------- src/common/buffer/BufferSet.ts | 18 ++++++++++-------- src/common/buffer/Types.d.ts | 1 + src/common/services/BufferService.ts | 3 +-- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/browser/public/Terminal.ts b/src/browser/public/Terminal.ts index 517f7c4f..70247f88 100644 --- a/src/browser/public/Terminal.ts +++ b/src/browser/public/Terminal.ts @@ -60,9 +60,8 @@ export class Terminal implements ITerminalApi { public get cols(): number { return this._core.cols; } public get buffer(): IBufferNamespaceApi { this._checkProposedApi(); - this._core.reset(); if (!this._buffer) { - this._buffer = new BufferNamespaceApi(this._core.buffers); + this._buffer = new BufferNamespaceApi(this._core); } return this._buffer; } @@ -251,21 +250,21 @@ class BufferNamespaceApi implements IBufferNamespaceApi { private _onBufferChange = new EventEmitter(); public get onBufferChange(): IEvent { return this._onBufferChange.event; } - constructor(private _buffers: IBufferSet) { - this._normal = new BufferApiView(this._buffers.normal, 'normal'); - this._alternate = new BufferApiView(this._buffers.alt, 'alternate'); - this._buffers.onBufferActivate(() => this._onBufferChange.fire(this.active)); + constructor(private _core: ITerminal) { + this._normal = new BufferApiView(this._core.buffers.normal, 'normal'); + this._alternate = new BufferApiView(this._core.buffers.alt, 'alternate'); + this._core.buffers.onBufferActivate(() => this._onBufferChange.fire(this.active)); } public get active(): IBufferApi { - if (this._buffers.active === this._buffers.normal) { return this.normal; } - if (this._buffers.active === this._buffers.alt) { return this.alternate; } + if (this._core.buffers.active === this._core.buffers.normal) { return this.normal; } + if (this._core.buffers.active === this._core.buffers.alt) { return this.alternate; } throw new Error('Active buffer is neither normal nor alternate'); } public get normal(): IBufferApi { - return this._normal.init(this._buffers.normal); + return this._normal.init(this._core.buffers.normal); } public get alternate(): IBufferApi { - return this._alternate.init(this._buffers.alt); + return this._alternate.init(this._core.buffers.alt); } } diff --git a/src/common/buffer/BufferSet.ts b/src/common/buffer/BufferSet.ts index b9dc7995..b74c4eac 100644 --- a/src/common/buffer/BufferSet.ts +++ b/src/common/buffer/BufferSet.ts @@ -15,10 +15,9 @@ import { Disposable } from 'common/Lifecycle'; * provides also utilities for working with them. */ export class BufferSet extends Disposable implements IBufferSet { - private _normal: Buffer; - private _alt: Buffer; - private _activeBuffer: Buffer; - + private _normal!: Buffer; + private _alt!: Buffer; + private _activeBuffer!: Buffer; private _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>()); public get onBufferActivate(): IEvent<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}> { return this._onBufferActivate.event; } @@ -28,17 +27,20 @@ export class BufferSet extends Disposable implements IBufferSet { * @param _terminal - The terminal the BufferSet will belong to */ constructor( - optionsService: IOptionsService, - bufferService: IBufferService + private readonly _optionsService: IOptionsService, + private readonly _bufferService: IBufferService ) { super(); + this.reset(); + } - this._normal = new Buffer(true, optionsService, bufferService); + public reset(): void { + this._normal = new Buffer(true, this._optionsService, this._bufferService); this._normal.fillViewportRows(); // The alt buffer should never have scrollback. // See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer - this._alt = new Buffer(false, optionsService, bufferService); + this._alt = new Buffer(false, this._optionsService, this._bufferService); this._activeBuffer = this._normal; this.setupTabStops(); diff --git a/src/common/buffer/Types.d.ts b/src/common/buffer/Types.d.ts index 752b1a26..cbf40a03 100644 --- a/src/common/buffer/Types.d.ts +++ b/src/common/buffer/Types.d.ts @@ -56,6 +56,7 @@ export interface IBufferSet extends IDisposable { activateNormalBuffer(): void; activateAltBuffer(fillAttr?: IAttributeData): void; + reset(): void; resize(newCols: number, newRows: number): void; setupTabStops(i?: number): void; } diff --git a/src/common/services/BufferService.ts b/src/common/services/BufferService.ts index 301146e1..47e54729 100644 --- a/src/common/services/BufferService.ts +++ b/src/common/services/BufferService.ts @@ -49,8 +49,7 @@ export class BufferService extends Disposable implements IBufferService { } public reset(): void { - this.buffers.dispose(); - this.buffers = new BufferSet(this._optionsService, this); + this.buffers.reset(); this.isUserScrolling = false; } }