From 311f6b6e84c5e713064c6e462042cd63f85de8a7 Mon Sep 17 00:00:00 2001 From: Vadim Zakondyrin Date: Fri, 7 Jun 2019 14:12:45 +0600 Subject: [PATCH 1/2] Fix saved cursor position on resize of alt screen --- src/InputHandler.ts | 4 ++-- src/common/buffer/Buffer.ts | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 5ea20caf..60693994 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 1e6edae9..a30274b6 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 From 699e721c4587faa548c9c9f258f7c4a52000c60a Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 15 Jun 2019 13:17:43 -0700 Subject: [PATCH 2/2] Add a test for DECRC --- test/InputHandler.api.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/InputHandler.api.ts b/test/InputHandler.api.ts index 3a95feca..cbf5dbd6 100644 --- a/test/InputHandler.api.ts +++ b/test/InputHandler.api.ts @@ -292,6 +292,23 @@ describe('InputHandler Integration Tests', function(): void { assert.deepEqual(await getLinesAsArray(3), ['#', ' #', 'abcd####']); }); }); + + describe('ESC', () => { + describe('DECRC: Save cursor, ESC 7', () => { + it('should save the absolute cursor position so resizing restores to the correct position', async () => { + await page.evaluate(` + window.term.resize(10, 2); + window.term.write('1\\n\\r2\\n\\r3\\n\\r4\\n\\r5'); + window.term.write('\\x1b7\\x1b[?47h'); + `); + await page.evaluate(` + window.term.resize(10, 4); + window.term.write('\\x1b[?47l\\x1b8'); + `); + assert.deepEqual(await getCursor(), {col: 1, row: 3}); + }); + }); + }); }); async function openTerminal(options: ITerminalOptions = {}): Promise {