Skip to content

Commit 7145130

Browse files
committed
Fix onBufferChange event not working after reset
Co-authored-by: Megan Rogge (megan.rogge@microsoft.com)
1 parent b34289c commit 7145130

4 files changed

Lines changed: 21 additions & 20 deletions

File tree

src/browser/public/Terminal.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ export class Terminal implements ITerminalApi {
6060
public get cols(): number { return this._core.cols; }
6161
public get buffer(): IBufferNamespaceApi {
6262
this._checkProposedApi();
63-
this._core.reset();
6463
if (!this._buffer) {
65-
this._buffer = new BufferNamespaceApi(this._core.buffers);
64+
this._buffer = new BufferNamespaceApi(this._core);
6665
}
6766
return this._buffer;
6867
}
@@ -251,21 +250,21 @@ class BufferNamespaceApi implements IBufferNamespaceApi {
251250
private _onBufferChange = new EventEmitter<IBufferApi>();
252251
public get onBufferChange(): IEvent<IBufferApi> { return this._onBufferChange.event; }
253252

254-
constructor(private _buffers: IBufferSet) {
255-
this._normal = new BufferApiView(this._buffers.normal, 'normal');
256-
this._alternate = new BufferApiView(this._buffers.alt, 'alternate');
257-
this._buffers.onBufferActivate(() => this._onBufferChange.fire(this.active));
253+
constructor(private _core: ITerminal) {
254+
this._normal = new BufferApiView(this._core.buffers.normal, 'normal');
255+
this._alternate = new BufferApiView(this._core.buffers.alt, 'alternate');
256+
this._core.buffers.onBufferActivate(() => this._onBufferChange.fire(this.active));
258257
}
259258
public get active(): IBufferApi {
260-
if (this._buffers.active === this._buffers.normal) { return this.normal; }
261-
if (this._buffers.active === this._buffers.alt) { return this.alternate; }
259+
if (this._core.buffers.active === this._core.buffers.normal) { return this.normal; }
260+
if (this._core.buffers.active === this._core.buffers.alt) { return this.alternate; }
262261
throw new Error('Active buffer is neither normal nor alternate');
263262
}
264263
public get normal(): IBufferApi {
265-
return this._normal.init(this._buffers.normal);
264+
return this._normal.init(this._core.buffers.normal);
266265
}
267266
public get alternate(): IBufferApi {
268-
return this._alternate.init(this._buffers.alt);
267+
return this._alternate.init(this._core.buffers.alt);
269268
}
270269
}
271270

src/common/buffer/BufferSet.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import { Disposable } from 'common/Lifecycle';
1515
* provides also utilities for working with them.
1616
*/
1717
export class BufferSet extends Disposable implements IBufferSet {
18-
private _normal: Buffer;
19-
private _alt: Buffer;
20-
private _activeBuffer: Buffer;
21-
18+
private _normal!: Buffer;
19+
private _alt!: Buffer;
20+
private _activeBuffer!: Buffer;
2221

2322
private _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>());
2423
public get onBufferActivate(): IEvent<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}> { return this._onBufferActivate.event; }
@@ -28,17 +27,20 @@ export class BufferSet extends Disposable implements IBufferSet {
2827
* @param _terminal - The terminal the BufferSet will belong to
2928
*/
3029
constructor(
31-
optionsService: IOptionsService,
32-
bufferService: IBufferService
30+
private readonly _optionsService: IOptionsService,
31+
private readonly _bufferService: IBufferService
3332
) {
3433
super();
34+
this.reset();
35+
}
3536

36-
this._normal = new Buffer(true, optionsService, bufferService);
37+
public reset(): void {
38+
this._normal = new Buffer(true, this._optionsService, this._bufferService);
3739
this._normal.fillViewportRows();
3840

3941
// The alt buffer should never have scrollback.
4042
// See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
41-
this._alt = new Buffer(false, optionsService, bufferService);
43+
this._alt = new Buffer(false, this._optionsService, this._bufferService);
4244
this._activeBuffer = this._normal;
4345

4446
this.setupTabStops();

src/common/buffer/Types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export interface IBufferSet extends IDisposable {
5656

5757
activateNormalBuffer(): void;
5858
activateAltBuffer(fillAttr?: IAttributeData): void;
59+
reset(): void;
5960
resize(newCols: number, newRows: number): void;
6061
setupTabStops(i?: number): void;
6162
}

src/common/services/BufferService.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ export class BufferService extends Disposable implements IBufferService {
4949
}
5050

5151
public reset(): void {
52-
this.buffers.dispose();
53-
this.buffers = new BufferSet(this._optionsService, this);
52+
this.buffers.reset();
5453
this.isUserScrolling = false;
5554
}
5655
}

0 commit comments

Comments
 (0)