diff --git a/src/BufferSet.ts b/src/BufferSet.ts index 0429c52365..c9022a9ced 100644 --- a/src/BufferSet.ts +++ b/src/BufferSet.ts @@ -30,21 +30,13 @@ export class BufferSet extends EventEmitter { return this._normal; } - private resetTerminal() { - this._terminal.reset(); - this._terminal.viewport.syncScrollArea(); - this._terminal.showCursor(); - } - public activateNormalBuffer(): void { this._activeBuffer = this._normal; - this.resetTerminal(); - this.emit('activate', this._normal); + this.emit('activate', this._normal); // todo maybe simpler this._terminal.buffer = this._terminal.buffers.normal than using EventEmitter? } public activateAltBuffer(): void { this._activeBuffer = this._alt; - this.resetTerminal(); - this.emit('activate', this._alt); + this.emit('activate', this._alt); // todo maybe simpler this._terminal.buffer = this._terminal.buffers.alt than using EventEmitter? } } diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 4b7ce1d2bd..4b920b48eb 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -940,16 +940,14 @@ export class InputHandler implements IInputHandler { this._terminal.cursorHidden = false; break; case 1049: // alt screen buffer cursor - // this._terminal.saveCursor(); - ; // FALL-THROUGH + this.saveCursor(params); + // FALL-THROUGH case 47: // alt screen buffer case 1047: // alt screen buffer - if (!this._terminal.normal) { - let normal = { - scrollBottom: this._terminal.buffer.scrollBottom, - }; - this._terminal.buffers.activateAltBuffer(); - } + this._terminal.buffers.activateAltBuffer(); + this._terminal.reset(); + this._terminal.viewport.syncScrollArea(); + this._terminal.showCursor(); break; } } @@ -1112,6 +1110,9 @@ export class InputHandler implements IInputHandler { case 1047: // normal screen buffer - clearing it first // Ensure the selection manager has the correct buffer this._terminal.buffers.activateNormalBuffer(); + if (params[0] === 1049) { + this.restoreCursor(params); + } this._terminal.selectionManager.setBuffer(this._terminal.buffer.lines); this._terminal.refresh(0, this._terminal.rows - 1); this._terminal.viewport.syncScrollArea(); @@ -1444,8 +1445,8 @@ export class InputHandler implements IInputHandler { * Save cursor (ANSI.SYS). */ public saveCursor(params: number[]): void { - this._terminal.savedX = this._terminal.buffer.x; - this._terminal.savedY = this._terminal.buffer.y; + this._terminal.buffers.active.x = this._terminal.buffer.x; + this._terminal.buffers.active.y = this._terminal.buffer.y; } @@ -1454,8 +1455,8 @@ export class InputHandler implements IInputHandler { * Restore cursor (ANSI.SYS). */ public restoreCursor(params: number[]): void { - this._terminal.buffer.x = this._terminal.savedX || 0; - this._terminal.buffer.y = this._terminal.savedY || 0; + this._terminal.buffer.x = this._terminal.buffers.active.x || 0; + this._terminal.buffer.y = this._terminal.buffers.active.y || 0; } } diff --git a/src/xterm.js b/src/xterm.js index 6357ab2116..44f21f467c 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -160,7 +160,6 @@ function Terminal(options) { this.originMode = false; this.insertMode = false; this.wraparoundMode = true; // defaults: xterm - true, vt100 - false - this.normal = null; // charset this.charset = null; @@ -227,10 +226,12 @@ function Terminal(options) { this.surrogate_high = ''; // Create the terminal's buffers and set the current buffer - this.buffers = new BufferSet(this); - this.buffer = this.buffers.active; // Convenience shortcut; + if (!this.buffers) { + this.buffers = new BufferSet(this); + this.buffer = this.buffers.active; // Convenience shortcut; + } this.buffers.on('activate', function (buffer) { - this.buffer = buffer; + this._terminal.buffer = buffer; }); /** @@ -2017,8 +2018,6 @@ Terminal.prototype.resize = function(x, y) { this.refresh(0, this.rows - 1); - this.normal = null; - this.geometry = [this.cols, this.rows]; this.emit('resize', {terminal: this, cols: x, rows: y}); }; @@ -2291,9 +2290,13 @@ Terminal.prototype.reset = function() { this.options.cols = this.cols; var customKeyEventHandler = this.customKeyEventHandler; var cursorBlinkInterval = this.cursorBlinkInterval; + var inputHandler = this.inputHandler; + var buf = this.buffers; Terminal.call(this, this.options); this.customKeyEventHandler = customKeyEventHandler; this.cursorBlinkInterval = cursorBlinkInterval; + this.inputHandler = inputHandler; + this.buffers = buf; this.refresh(0, this.rows - 1); this.viewport.syncScrollArea(); };