diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 5ea20caf4..606939942 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -1916,7 +1916,7 @@ export class InputHandler extends Disposable implements IInputHandler { */ public saveCursor(params: number[]): void { this._terminal.buffer.savedX = this._terminal.buffer.x; - this._terminal.buffer.savedY = this._terminal.buffer.y; + this._terminal.buffer.savedY = this._terminal.buffer.ybase + this._terminal.buffer.y; this._terminal.buffer.savedCurAttrData.fg = this._terminal.curAttrData.fg; this._terminal.buffer.savedCurAttrData.bg = this._terminal.curAttrData.bg; } @@ -1929,7 +1929,7 @@ export class InputHandler extends Disposable implements IInputHandler { */ public restoreCursor(params: number[]): void { this._terminal.buffer.x = this._terminal.buffer.savedX || 0; - this._terminal.buffer.y = this._terminal.buffer.savedY || 0; + this._terminal.buffer.y = Math.max(this._terminal.buffer.savedY - this._terminal.buffer.ybase, 0); this._terminal.curAttrData.fg = this._terminal.buffer.savedCurAttrData.fg; this._terminal.curAttrData.bg = this._terminal.buffer.savedCurAttrData.bg; } diff --git a/src/common/buffer/Buffer.ts b/src/common/buffer/Buffer.ts index 1e6edae90..a30274b6e 100644 --- a/src/common/buffer/Buffer.ts +++ b/src/common/buffer/Buffer.ts @@ -124,6 +124,7 @@ export class Buffer implements IBuffer { public clear(): void { this.ydisp = 0; this.ybase = 0; + this.savedY = 0; this.y = 0; this.x = 0; this.lines = new CircularList(this._getCorrectBufferLength(this._rows)); @@ -203,6 +204,7 @@ export class Buffer implements IBuffer { this.lines.trimStart(amountToTrim); this.ybase = Math.max(this.ybase - amountToTrim, 0); this.ydisp = Math.max(this.ydisp - amountToTrim, 0); + this.savedY = Math.max(this.savedY - amountToTrim, 0); } this.lines.maxLength = newMaxLength; } @@ -213,7 +215,6 @@ export class Buffer implements IBuffer { if (addToY) { this.y += addToY; } - this.savedY = Math.min(this.savedY, newRows - 1); this.savedX = Math.min(this.savedX, newCols - 1); this.scrollTop = 0; @@ -282,6 +283,7 @@ export class Buffer implements IBuffer { this.ybase--; } } + this.savedY = Math.max(this.savedY - countRemoved, 0); } private _reflowSmaller(newCols: number, newRows: number): void { @@ -393,6 +395,7 @@ export class Buffer implements IBuffer { } } } + this.savedY = Math.min(this.savedY + linesToAdd, this.ybase + newRows - 1); } // Rearrange lines in the buffer if there are any insertions, this is done at the end rather