Discard cut off combined data when resizing BufferLines

This commit is contained in:
Daniel Imms
2018-12-31 10:26:10 -08:00
parent db488ebcc9
commit 40e8618cf5
2 changed files with 22 additions and 0 deletions
+13
View File
@@ -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 {
+9
View File
@@ -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;