From 4c36ef9d24d0ab899d094a94bc5e20beb6b54afd Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 10 Apr 2020 09:56:26 -0700 Subject: [PATCH] Don't pass buffers to BufferApiView --- src/public/Terminal.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/public/Terminal.ts b/src/public/Terminal.ts index fbf3fb487..61334f08a 100644 --- a/src/public/Terminal.ts +++ b/src/public/Terminal.ts @@ -193,19 +193,16 @@ export class Terminal implements ITerminalApi { } class BufferApiView implements IBufferApi { - constructor(private _buffer: IBuffer, private _buffers: IBufferSet) { } + constructor( + private _buffer: IBuffer, + public readonly type: 'normal' | 'alternate' + ) { } - init(buffer: IBuffer, buffers: IBufferSet): BufferApiView { + public init(buffer: IBuffer): BufferApiView { this._buffer = buffer; - this._buffers = buffers; return this; } - public get type(): 'normal' | 'alternate' { - if (this._buffers.normal === this._buffer) { return 'normal'; } - if (this._buffers.alt === this._buffer) { return 'alternate'; } - throw new Error('Unknown buffer type'); - } public get cursorY(): number { return this._buffer.y; } public get cursorX(): number { return this._buffer.x; } public get viewportY(): number { return this._buffer.ydisp; } @@ -228,18 +225,21 @@ class BufferNamespaceApi implements IBufferNamespaceApi { public get onBufferChange(): IEvent { return this._onBufferChange.event; } constructor(private _buffers: IBufferSet) { - this._normal = new BufferApiView(this._buffers.normal, this._buffers); - this._alternate = new BufferApiView(this._buffers.alt, this._buffers); + this._normal = new BufferApiView(this._buffers.normal, 'normal'); + this._alternate = new BufferApiView(this._buffers.alt, 'alternate'); this._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; } throw new Error('Active buffer is neither normal nor alternate'); } - public get normal(): IBufferApi { return this._normal.init(this._buffers.normal, this._buffers); } - public get alternate(): IBufferApi { return this._alternate.init(this._buffers.alt, this._buffers); } + public get normal(): IBufferApi { + return this._normal.init(this._buffers.normal); + } + public get alternate(): IBufferApi { + return this._alternate.init(this._buffers.alt); + } } class BufferLineApiView implements IBufferLineApi {