Merge pull request #2217 from termius/fix-cursor

Fix saved cursor position on resize of alt screen
This commit is contained in:
Daniel Imms
2019-06-15 13:22:19 -07:00
committed by GitHub
3 changed files with 23 additions and 3 deletions
+2 -2
View File
@@ -1919,7 +1919,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;
}
@@ -1932,7 +1932,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;
}
+4 -1
View File
@@ -126,6 +126,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<IBufferLine>(this._getCorrectBufferLength(this._rows));
@@ -205,6 +206,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;
}
@@ -215,7 +217,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;
@@ -284,6 +285,7 @@ export class Buffer implements IBuffer {
this.ybase--;
}
}
this.savedY = Math.max(this.savedY - countRemoved, 0);
}
private _reflowSmaller(newCols: number, newRows: number): void {
@@ -395,6 +397,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
+17
View File
@@ -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<void> {