Skip to content

Commit

Permalink
Merge pull request #145989 from microsoft/tyriar/145920
Browse files Browse the repository at this point in the history
Clear viewport commands in partial detection on CSI 2/3 J
  • Loading branch information
Tyriar authored Mar 24, 2022
2 parents 43ca538 + ab56599 commit 8fc399c
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export class PartialCommandDetectionCapability implements IPartialCommandDetecti
private readonly _terminal: Terminal,
) {
this._terminal.onData(e => this._onData(e));
this._terminal.parser.registerCsiHandler({ final: 'J' }, params => {
if (params.length >= 1 && (params[0] === 2 || params[0] === 3)) {
this._clearCommandsInViewport();
}
// We don't want to override xterm.js' default behavior, just augment it
return false;
});
}

private _onData(data: string): void {
Expand All @@ -54,4 +61,17 @@ export class PartialCommandDetectionCapability implements IPartialCommandDetecti
}
}
}

private _clearCommandsInViewport(): void {
// Find the number of commands on the tail end of the array that are within the viewport
let count = 0;
for (let i = this._commands.length - 1; i >= 0; i--) {
if (this._commands[i].line < this._terminal.buffer.active.baseY) {
break;
}
count++;
}
// Remove them
this._commands.splice(this._commands.length - count, count);
}
}

0 comments on commit 8fc399c

Please sign in to comment.