From 40e8618cf5810e61b8d42e6d0a1d37aab31516f3 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 31 Dec 2018 10:26:10 -0800 Subject: [PATCH] Discard cut off combined data when resizing BufferLines --- src/BufferLine.test.ts | 13 +++++++++++++ src/BufferLine.ts | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/src/BufferLine.test.ts b/src/BufferLine.test.ts index c652ff4e..f5e95fc8 100644 --- a/src/BufferLine.test.ts +++ b/src/BufferLine.test.ts @@ -9,6 +9,10 @@ import { NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, DEFAULT_ATTR } from '. class TestBufferLine extends BufferLine { + public get combined(): {[index: number]: string} { + return this._combined; + } + public toArray(): CharData[] { const result = []; for (let i = 0; i < this.length; ++i) { @@ -154,6 +158,15 @@ describe('BufferLine', function(): void { line.resize(0, [1, 'a', 0, 'a'.charCodeAt(0)]); chai.expect(line.toArray()).eql(Array(0).fill([1, 'a', 0, 'a'.charCodeAt(0)])); }); + it('should remove combining data', () => { + const line = new TestBufferLine(10, [1, 'a', 0, 'a'.charCodeAt(0)], false); + line.set(9, [ null, '😁', 1, '😁'.charCodeAt(0) ]); + chai.expect(line.translateToString()).eql('aaaaaaaaa😁'); + chai.expect(Object.keys(line.combined).length).eql(1); + line.resize(5, [1, 'a', 0, 'a'.charCodeAt(0)]); + chai.expect(line.translateToString()).eql('aaaaa'); + chai.expect(Object.keys(line.combined).length).eql(0); + }); }); describe('getTrimLength', function(): void { it('empty line', function(): void { diff --git a/src/BufferLine.ts b/src/BufferLine.ts index 619fa9ca..1c391471 100644 --- a/src/BufferLine.ts +++ b/src/BufferLine.ts @@ -250,8 +250,17 @@ export class BufferLine implements IBufferLine { const data = new Uint32Array(cols * CELL_SIZE); data.set(this._data.subarray(0, cols * CELL_SIZE)); this._data = data; + // Remove any cut off combined data + const keys = Object.keys(this._combined); + for (let i = 0; i < keys.length; i++) { + const key = parseInt(keys[i], 10); + if (key >= cols) { + delete this._combined[key]; + } + } } else { this._data = null; + this._combined = {}; } } this.length = cols;