Skip to content

Commit febc3ba

Browse files
authored
Merge pull request #1736 from jerch/fix_bufferline_resize
fix BufferLine resize
2 parents f2c7de8 + 1c5dfb5 commit febc3ba

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/BufferLine.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,31 @@ describe('BufferLine', function(): void {
133133
const line3 = line.clone();
134134
chai.expect(TestBufferLine.prototype.toArray.apply(line3)).eql(line.toArray());
135135
});
136+
it('resize enlarge', function(): void {
137+
const line = new TestBufferLine(5, [1, 'a', 0, 'a'.charCodeAt(0)], false);
138+
line.resize(10, [1, 'a', 0, 'a'.charCodeAt(0)]);
139+
chai.expect(line.toArray()).eql(Array(10).fill([1, 'a', 0, 'a'.charCodeAt(0)]));
140+
});
141+
it('resize shrink(true)', function(): void {
142+
const line = new TestBufferLine(10, [1, 'a', 0, 'a'.charCodeAt(0)], false);
143+
line.resize(5, [1, 'a', 0, 'a'.charCodeAt(0)], true);
144+
chai.expect(line.toArray()).eql(Array(5).fill([1, 'a', 0, 'a'.charCodeAt(0)]));
145+
});
146+
it('resize shrink(false)', function(): void {
147+
const line = new TestBufferLine(10, [1, 'a', 0, 'a'.charCodeAt(0)], false);
148+
line.resize(5, [1, 'a', 0, 'a'.charCodeAt(0)], false);
149+
chai.expect(line.toArray()).eql(Array(5).fill([1, 'a', 0, 'a'.charCodeAt(0)]));
150+
});
151+
it('resize shrink(false) + shrink(false)', function(): void {
152+
const line = new TestBufferLine(20, [1, 'a', 0, 'a'.charCodeAt(0)], false);
153+
line.resize(10, [1, 'a', 0, 'a'.charCodeAt(0)], false);
154+
line.resize(5, [1, 'a', 0, 'a'.charCodeAt(0)], false);
155+
chai.expect(line.toArray()).eql(Array(5).fill([1, 'a', 0, 'a'.charCodeAt(0)]));
156+
});
157+
it('resize shrink(false) + enlarge', function(): void {
158+
const line = new TestBufferLine(20, [1, 'a', 0, 'a'.charCodeAt(0)], false);
159+
line.resize(10, [1, 'a', 0, 'a'.charCodeAt(0)], false);
160+
line.resize(15, [1, 'a', 0, 'a'.charCodeAt(0)]);
161+
chai.expect(line.toArray()).eql(Array(15).fill([1, 'a', 0, 'a'.charCodeAt(0)]));
162+
});
136163
});

src/BufferLine.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ export class BufferLineTypedArray implements IBufferLine {
218218
if (cols > this.length) {
219219
const data = new Uint32Array(cols * CELL_SIZE);
220220
if (this._data) {
221-
data.set(this._data);
221+
if (cols * CELL_SIZE < this._data.length) {
222+
data.set(this._data.subarray(0, cols * CELL_SIZE));
223+
} else {
224+
data.set(this._data);
225+
}
222226
}
223227
this._data = data;
224228
for (let i = this.length; i < cols; ++i) {

0 commit comments

Comments
 (0)