Skip to content

Commit ab56599

Browse files
committed
Clear viewport commands in partial detection on CSI 2/3 J
Fixes microsoft#145920
1 parent 43ca538 commit ab56599

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/vs/platform/terminal/common/capabilities/partialCommandDetectionCapability.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ export class PartialCommandDetectionCapability implements IPartialCommandDetecti
3434
private readonly _terminal: Terminal,
3535
) {
3636
this._terminal.onData(e => this._onData(e));
37+
this._terminal.parser.registerCsiHandler({ final: 'J' }, params => {
38+
if (params.length >= 1 && (params[0] === 2 || params[0] === 3)) {
39+
this._clearCommandsInViewport();
40+
}
41+
// We don't want to override xterm.js' default behavior, just augment it
42+
return false;
43+
});
3744
}
3845

3946
private _onData(data: string): void {
@@ -54,4 +61,17 @@ export class PartialCommandDetectionCapability implements IPartialCommandDetecti
5461
}
5562
}
5663
}
64+
65+
private _clearCommandsInViewport(): void {
66+
// Find the number of commands on the tail end of the array that are within the viewport
67+
let count = 0;
68+
for (let i = this._commands.length - 1; i >= 0; i--) {
69+
if (this._commands[i].line < this._terminal.buffer.active.baseY) {
70+
break;
71+
}
72+
count++;
73+
}
74+
// Remove them
75+
this._commands.splice(this._commands.length - count, count);
76+
}
5777
}

0 commit comments

Comments
 (0)