diff --git a/src/vs/platform/terminal/common/capabilities/partialCommandDetectionCapability.ts b/src/vs/platform/terminal/common/capabilities/partialCommandDetectionCapability.ts index 1a722cd14da2f..932413459a3f0 100644 --- a/src/vs/platform/terminal/common/capabilities/partialCommandDetectionCapability.ts +++ b/src/vs/platform/terminal/common/capabilities/partialCommandDetectionCapability.ts @@ -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 { @@ -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); + } }