From 88da52483a27017b15bd1e045edb0543a1a65a98 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 24 Mar 2022 08:44:10 -0700 Subject: [PATCH] Clear viewport commands in partial detection on CSI 2/3 J Fixes #145920 --- .../partialCommandDetectionCapability.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/vs/platform/terminal/common/capabilities/partialCommandDetectionCapability.ts b/src/vs/platform/terminal/common/capabilities/partialCommandDetectionCapability.ts index 1a722cd14da2f3..932413459a3f0a 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); + } }