diff --git a/src/InputHandler.test.ts b/src/InputHandler.test.ts index 4329fa1a..541547f8 100644 --- a/src/InputHandler.test.ts +++ b/src/InputHandler.test.ts @@ -1062,6 +1062,20 @@ describe('InputHandler', () => { term.writeSync('0123456789\x1b[X'); assert.equal(term.buffer.lines.get(0).translateToString(false), '012345678 '); }); + it('ICH', () => { + term.buffer.x = 10000; + term.buffer.y = 10000; + term.writeSync('\x1b[@'); + assert.deepEqual(getCursor(term), [9, 9]); + term.buffer.x = -10000; + term.buffer.y = -10000; + term.writeSync('\x1b[@'); + assert.deepEqual(getCursor(term), [0, 0]); + }); + it('ICH - should delete last cell', () => { + term.writeSync('0123456789\x1b[@'); + assert.equal(term.buffer.lines.get(0).translateToString(false), '012345678 '); + }); }); }); }); diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 718efcc8..5fae95f9 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -586,12 +586,15 @@ export class InputHandler extends Disposable implements IInputHandler { */ public insertChars(params: IParams): void { this._restrictCursor(); - this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).insertCells( - this._terminal.buffer.x, - params.params[0] || 1, - this._terminal.buffer.getNullCell(this._terminal.eraseAttrData()) - ); - this._terminal.updateRange(this._terminal.buffer.y); + const line = this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase); + if (line) { + line.insertCells( + this._terminal.buffer.x, + params.params[0] || 1, + this._terminal.buffer.getNullCell(this._terminal.eraseAttrData()) + ); + this._terminal.updateRange(this._terminal.buffer.y); + } } /**