Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dispose of markers on buffer clear #3628

Merged
merged 7 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/browser/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
// Don't clear if it's already clear
return;
}
this.buffer.clearMarkers();
this.buffer.lines.set(0, this.buffer.lines.get(this.buffer.ybase + this.buffer.y)!);
this.buffer.lines.length = 1;
this.buffer.ydisp = 0;
Expand Down
15 changes: 14 additions & 1 deletion src/common/buffer/Buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DEFAULT_CHARSET } from 'common/data/Charsets';
import { ExtendedAttrs } from 'common/buffer/AttributeData';

export const MAX_BUFFER_SIZE = 4294967295; // 2^32 - 1
const enum BufferState { CLEARING = 'clearing' }

/**
* This class represents a terminal buffer (an internal state of the terminal), where the
Expand Down Expand Up @@ -43,6 +44,7 @@ export class Buffer implements IBuffer {
private _whitespaceCell: ICellData = CellData.fromCharData([0, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_WIDTH, WHITESPACE_CELL_CODE]);
private _cols: number;
private _rows: number;
private _state: string | undefined;
meganrogge marked this conversation as resolved.
Show resolved Hide resolved

constructor(
private _hasScrollback: boolean,
Expand Down Expand Up @@ -584,6 +586,15 @@ export class Buffer implements IBuffer {
return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x;
}

public clearMarkers(): void {
this._state = BufferState.CLEARING;
for (const marker of this.markers) {
marker.dispose();
}
this.markers = [];
this._state = undefined;
}

public addMarker(y: number): Marker {
const marker = new Marker(y);
this.markers.push(marker);
Expand Down Expand Up @@ -615,7 +626,9 @@ export class Buffer implements IBuffer {
}

private _removeMarker(marker: Marker): void {
this.markers.splice(this.markers.indexOf(marker), 1);
if (this._state !== BufferState.CLEARING) {
this.markers.splice(this.markers.indexOf(marker), 1);
}
}

public iterator(trimRight: boolean, startIndex?: number, endIndex?: number, startOverscan?: number, endOverscan?: number): IBufferStringIterator {
Expand Down
1 change: 1 addition & 0 deletions src/common/buffer/Types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface IBuffer {
getNullCell(attr?: IAttributeData): ICellData;
getWhitespaceCell(attr?: IAttributeData): ICellData;
addMarker(y: number): IMarker;
clearMarkers(): void;
}

export interface IBufferSet extends IDisposable {
Expand Down