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

during buffer clear, don't dispose of markers on first line #3671

Merged
merged 7 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/browser/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/browser/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}
Expand Down
34 changes: 23 additions & 11 deletions src/common/buffer/Buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,20 +585,32 @@ export class Buffer implements IBuffer {
return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x;
}

public clearMarkers(y?: number): void {
/**
* Clears markers on single line.
* @param y The line to clear.
*/
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);
}
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 {
for (const marker of this.markers) {
marker.dispose();
}
this._isClearing = false;
}

/**
* 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;
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.markers = [];
}
this._isClearing = false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/common/buffer/Types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
}

export interface IBufferSet extends IDisposable {
Expand Down