diff --git a/src/InputHandler.test.ts b/src/InputHandler.test.ts index a39ad9b9..2ebac006 100644 --- a/src/InputHandler.test.ts +++ b/src/InputHandler.test.ts @@ -1034,6 +1034,20 @@ describe('InputHandler', () => { term.writeSync('\x1b[e'); assert.deepEqual(getCursor(term), [0, 1]); }); + it('DCH', () => { + term.buffer.x = 10000; + term.buffer.y = 10000; + term.writeSync('\x1b[P'); + assert.deepEqual(getCursor(term), [9, 9]); + term.buffer.x = -10000; + term.buffer.y = -10000; + term.writeSync('\x1b[P'); + assert.deepEqual(getCursor(term), [0, 0]); + }); + it('DCH - should delete last cell', () => { + term.writeSync('0123456789\x1b[P'); + assert.equal(term.buffer.lines.get(0).translateToString(false), '012345678 '); + }); }); }); }); diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 96832dfe..7cb6cd2d 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -895,12 +895,16 @@ export class InputHandler extends Disposable implements IInputHandler { * Delete Ps Character(s) (default = 1) (DCH). */ public deleteChars(params: IParams): void { - this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).deleteCells( - this._terminal.buffer.x, - params.params[0] || 1, - this._terminal.buffer.getNullCell(this._terminal.eraseAttrData()) - ); - this._terminal.updateRange(this._terminal.buffer.y); + this._restrictCursor(); + const line = this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase); + if (line) { + line.deleteCells( + this._terminal.buffer.x, + params.params[0] || 1, + this._terminal.buffer.getNullCell(this._terminal.eraseAttrData()) + ); + this._terminal.updateRange(this._terminal.buffer.y); + } } /**