From f5b66775db75ed7416b20b4fd37766d41fe25fea Mon Sep 17 00:00:00 2001 From: meganrogge Date: Wed, 2 Mar 2022 12:36:35 -0600 Subject: [PATCH 1/6] during buffer clear, don't dispose of markers on first line --- src/common/buffer/Buffer.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common/buffer/Buffer.ts b/src/common/buffer/Buffer.ts index 7596fef3f5..f7dc97d303 100644 --- a/src/common/buffer/Buffer.ts +++ b/src/common/buffer/Buffer.ts @@ -595,10 +595,14 @@ export class Buffer implements IBuffer { } } } else { - for (const marker of this.markers) { - marker.dispose(); + // buffer has been cleared + // don't dispose of markers on the current line (0) + for (let i = 0; i < this.markers.length; i++) { + if (this.markers[i].line !== 0) { + this.markers[i].dispose(); + this.markers.splice(i--, 1); + } } - this.markers = []; } this._isClearing = false; } From 7bf12f9123a0f8c133b1fdf41b74b72b0eab341c Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Wed, 2 Mar 2022 20:29:31 +0000 Subject: [PATCH 2/6] break into two methods --- src/common/buffer/Buffer.ts | 21 ++++++++++++++------- src/common/buffer/Types.d.ts | 3 ++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/common/buffer/Buffer.ts b/src/common/buffer/Buffer.ts index f7dc97d303..a4cc46037d 100644 --- a/src/common/buffer/Buffer.ts +++ b/src/common/buffer/Buffer.ts @@ -585,24 +585,31 @@ export class Buffer implements IBuffer { return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x; } - public clearMarkers(y?: number): void { + /** + * Clears markers on line @param y + */ + public clearMarkers(y: number): void { this._isClearing = true; - if (y !== undefined) { for (let i = 0; i < this.markers.length; i++) { if (this.markers[i].line === y) { this.markers[i].dispose(); this.markers.splice(i--, 1); } } - } else { - // buffer has been cleared - // don't dispose of markers on the current line (0) + this._isClearing = false; + } + + /** + * Clears markers on all lines except for + * those on @param excludeY + */ + public clearAllMarkers(excludeY: number): void { + this._isClearing = true; for (let i = 0; i < this.markers.length; i++) { - if (this.markers[i].line !== 0) { + if (this.markers[i].line !== excludeY) { this.markers[i].dispose(); this.markers.splice(i--, 1); } - } } this._isClearing = false; } diff --git a/src/common/buffer/Types.d.ts b/src/common/buffer/Types.d.ts index 36b70b7f36..f26b4b26f5 100644 --- a/src/common/buffer/Types.d.ts +++ b/src/common/buffer/Types.d.ts @@ -45,7 +45,8 @@ export interface IBuffer { getNullCell(attr?: IAttributeData): ICellData; getWhitespaceCell(attr?: IAttributeData): ICellData; addMarker(y: number): IMarker; - clearMarkers(y?: number): void; + clearMarkers(y: number): void; + clearAllMarkers(excludeY: number): void; } export interface IBufferSet extends IDisposable { From 85dd6a9e87bf61ace28be0ae7a13a6fba2cb7838 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Wed, 2 Mar 2022 15:18:24 -0600 Subject: [PATCH 3/6] Update src/common/buffer/Buffer.ts Co-authored-by: Daniel Imms <2193314+Tyriar@users.noreply.github.com> --- src/common/buffer/Buffer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/buffer/Buffer.ts b/src/common/buffer/Buffer.ts index a4cc46037d..8693736c94 100644 --- a/src/common/buffer/Buffer.ts +++ b/src/common/buffer/Buffer.ts @@ -586,7 +586,8 @@ export class Buffer implements IBuffer { } /** - * Clears markers on line @param y + * Clears markers on single line. + * @param y The line to clear. */ public clearMarkers(y: number): void { this._isClearing = true; From 1af22b24c021d6dba1cd94dd2346ab48f03345f0 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Wed, 2 Mar 2022 15:18:29 -0600 Subject: [PATCH 4/6] Update src/common/buffer/Buffer.ts Co-authored-by: Daniel Imms <2193314+Tyriar@users.noreply.github.com> --- src/common/buffer/Buffer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/buffer/Buffer.ts b/src/common/buffer/Buffer.ts index 8693736c94..bf9d24cecb 100644 --- a/src/common/buffer/Buffer.ts +++ b/src/common/buffer/Buffer.ts @@ -601,8 +601,8 @@ export class Buffer implements IBuffer { } /** - * Clears markers on all lines except for - * those on @param excludeY + * Clears markers on all lines except for those on a particular line. + * @param excludeY The line to exclude. */ public clearAllMarkers(excludeY: number): void { this._isClearing = true; From e75b47ca015addc198ee194aa52306903a42d0b8 Mon Sep 17 00:00:00 2001 From: meganrogge Date: Wed, 2 Mar 2022 15:21:17 -0600 Subject: [PATCH 5/6] use clearAllMarkers --- src/browser/Terminal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index 703c995be3..089639338d 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -1301,7 +1301,7 @@ export class Terminal extends CoreTerminal implements ITerminal { // Don't clear if it's already clear return; } - this.buffer.clearMarkers(); + this.buffer.clearAllMarkers(0); this.buffer.lines.set(0, this.buffer.lines.get(this.buffer.ybase + this.buffer.y)!); this.buffer.lines.length = 1; this.buffer.ydisp = 0; From 82706e77dbba4b69843c785a3ae6bc13723f9d41 Mon Sep 17 00:00:00 2001 From: meganrogge Date: Wed, 2 Mar 2022 20:19:49 -0600 Subject: [PATCH 6/6] add to mockbuffer --- src/browser/TestUtils.test.ts | 5 ++++- src/common/buffer/Buffer.ts | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/browser/TestUtils.test.ts b/src/browser/TestUtils.test.ts index 10a1435b81..ac048be665 100644 --- a/src/browser/TestUtils.test.ts +++ b/src/browser/TestUtils.test.ts @@ -257,7 +257,10 @@ export class MockBuffer implements IBuffer { public getWhitespaceCell(attr?: IAttributeData): ICellData { throw new Error('Method not implemented.'); } - public clearMarkers(): void { + public clearMarkers(y: number): void { + throw new Error('Method not implemented.'); + } + public clearAllMarkers(excludeY: number): void { throw new Error('Method not implemented.'); } } diff --git a/src/common/buffer/Buffer.ts b/src/common/buffer/Buffer.ts index bf9d24cecb..ab2957845f 100644 --- a/src/common/buffer/Buffer.ts +++ b/src/common/buffer/Buffer.ts @@ -591,12 +591,12 @@ export class Buffer implements IBuffer { */ public clearMarkers(y: number): void { this._isClearing = true; - for (let i = 0; i < this.markers.length; i++) { - if (this.markers[i].line === y) { - this.markers[i].dispose(); - this.markers.splice(i--, 1); - } + for (let i = 0; i < this.markers.length; i++) { + if (this.markers[i].line === y) { + this.markers[i].dispose(); + this.markers.splice(i--, 1); } + } this._isClearing = false; } @@ -604,13 +604,13 @@ export class Buffer implements IBuffer { * Clears markers on all lines except for those on a particular line. * @param excludeY The line to exclude. */ - public clearAllMarkers(excludeY: number): void { + public clearAllMarkers(excludeY: number): void { this._isClearing = true; - for (let i = 0; i < this.markers.length; i++) { - if (this.markers[i].line !== excludeY) { - this.markers[i].dispose(); - this.markers.splice(i--, 1); - } + for (let i = 0; i < this.markers.length; i++) { + if (this.markers[i].line !== excludeY) { + this.markers[i].dispose(); + this.markers.splice(i--, 1); + } } this._isClearing = false; }