Skip to content

Commit 72dbd43

Browse files
authored
Merge pull request #3204 from meganrogge/master
set this._buffer to new buffer
2 parents 4de6f1c + 7145130 commit 72dbd43

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

src/browser/public/Terminal.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as Strings from '../LocalizableStrings';
1313
import { IEvent, EventEmitter } from 'common/EventEmitter';
1414
import { AddonManager } from './AddonManager';
1515
import { IParams } from 'common/parser/Types';
16+
import { BufferSet } from 'common/buffer/BufferSet';
1617

1718
export class Terminal implements ITerminalApi {
1819
private _core: ITerminal;
@@ -60,7 +61,7 @@ export class Terminal implements ITerminalApi {
6061
public get buffer(): IBufferNamespaceApi {
6162
this._checkProposedApi();
6263
if (!this._buffer) {
63-
return new BufferNamespaceApi(this._core.buffers);
64+
this._buffer = new BufferNamespaceApi(this._core);
6465
}
6566
return this._buffer;
6667
}
@@ -249,21 +250,21 @@ class BufferNamespaceApi implements IBufferNamespaceApi {
249250
private _onBufferChange = new EventEmitter<IBufferApi>();
250251
public get onBufferChange(): IEvent<IBufferApi> { return this._onBufferChange.event; }
251252

252-
constructor(private _buffers: IBufferSet) {
253-
this._normal = new BufferApiView(this._buffers.normal, 'normal');
254-
this._alternate = new BufferApiView(this._buffers.alt, 'alternate');
255-
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));
256257
}
257258
public get active(): IBufferApi {
258-
if (this._buffers.active === this._buffers.normal) { return this.normal; }
259-
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; }
260261
throw new Error('Active buffer is neither normal nor alternate');
261262
}
262263
public get normal(): IBufferApi {
263-
return this._normal.init(this._buffers.normal);
264+
return this._normal.init(this._core.buffers.normal);
264265
}
265266
public get alternate(): IBufferApi {
266-
return this._alternate.init(this._buffers.alt);
267+
return this._alternate.init(this._core.buffers.alt);
267268
}
268269
}
269270

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)