diff --git a/src/BufferLine.ts b/src/BufferLine.ts index de36a968..170fc81d 100644 --- a/src/BufferLine.ts +++ b/src/BufferLine.ts @@ -17,20 +17,18 @@ export class BufferLineOld implements IBufferLine { public isWrapped = false; public length: number; - constructor(cols: number, ch?: CharData, isWrapped?: boolean) { + constructor(cols: number, fillCharData?: CharData, isWrapped?: boolean) { this._data = []; - this.length = this._data.length; - if (cols) { - if (!ch) { - ch = [0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]; - } - for (let i = 0; i < cols; i++) { - this._push(ch); // Note: the ctor ch is not cloned (resembles old behavior) - } + if (!fillCharData) { + fillCharData = [0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]; + } + for (let i = 0; i < cols; i++) { + this._push(fillCharData); // Note: the ctor ch is not cloned (resembles old behavior) } if (isWrapped) { this.isWrapped = true; } + this.length = this._data.length; } private _pop(): CharData | undefined { @@ -67,29 +65,29 @@ export class BufferLineOld implements IBufferLine { } /** delete n cells at pos, right side is filled with fill (stable length) */ - public deleteCells(pos: number, n: number, fill: CharData): void { + public deleteCells(pos: number, n: number, fillCharData: CharData): void { while (n--) { this._splice(pos, 1); - this._push(fill); + this._push(fillCharData); } } /** replace cells from pos to pos + n - 1 with fill */ - public replaceCells(start: number, end: number, fill: CharData): void { + public replaceCells(start: number, end: number, fillCharData: CharData): void { while (start < end && start < this.length) { - this.set(start++, fill); // Note: fill is not cloned (resembles old behavior) + this.set(start++, fillCharData); // Note: fill is not cloned (resembles old behavior) } } /** resize line to cols filling new cells with fill */ - public resize(cols: number, fill: CharData, shrink: boolean = false): void { + public resize(cols: number, fillCharData: CharData, shrink: boolean = false): void { if (shrink) { while (this._data.length > cols) { this._data.pop(); } } while (this._data.length < cols) { - this._data.push(fill); + this._data.push(fillCharData); } this.length = cols; } @@ -111,17 +109,15 @@ export class BufferLine implements IBufferLine { protected _combined: {[index: number]: string} = {}; public length: number; - constructor(cols: number, ch?: CharData, public isWrapped: boolean = false) { - this.length = cols || 0; - if (cols) { - if (!ch) { - ch = [0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]; - } - this._data = new Uint32Array(cols * Cell.SIZE); - for (let i = 0; i < cols; ++i) { - this.set(i, ch); - } + constructor(cols: number, fillCharData?: CharData, public isWrapped: boolean = false) { + if (!fillCharData) { + fillCharData = [0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]; } + this._data = new Uint32Array(cols * Cell.SIZE); + for (let i = 0; i < cols; ++i) { + this.set(i, fillCharData); + } + this.length = cols || 0; } public get(index: number): CharData { @@ -147,45 +143,45 @@ export class BufferLine implements IBufferLine { this._data[index * Cell.SIZE + Cell.WIDTH] = value[2]; } - public insertCells(pos: number, n: number, fill: CharData): void { + public insertCells(pos: number, n: number, fillCharData: CharData): void { pos %= this.length; if (n < this.length - pos) { for (let i = this.length - pos - n - 1; i >= 0; --i) { this.set(pos + n + i, this.get(pos + i)); } for (let i = 0; i < n; ++i) { - this.set(pos + i, fill); + this.set(pos + i, fillCharData); } } else { for (let i = pos; i < this.length; ++i) { - this.set(i, fill); + this.set(i, fillCharData); } } } - public deleteCells(pos: number, n: number, fill: CharData): void { + public deleteCells(pos: number, n: number, fillCharData: CharData): void { pos %= this.length; if (n < this.length - pos) { for (let i = 0; i < this.length - pos - n; ++i) { this.set(pos + i, this.get(pos + n + i)); } for (let i = this.length - n; i < this.length; ++i) { - this.set(i, fill); + this.set(i, fillCharData); } } else { for (let i = pos; i < this.length; ++i) { - this.set(i, fill); + this.set(i, fillCharData); } } } - public replaceCells(start: number, end: number, fill: CharData): void { + public replaceCells(start: number, end: number, fillCharData: CharData): void { while (start < end && start < this.length) { - this.set(start++, fill); + this.set(start++, fillCharData); } } - public resize(cols: number, fill: CharData, shrink: boolean = false): void { + public resize(cols: number, fillCharData: CharData, shrink: boolean = false): void { if (cols === this.length) { return; } @@ -196,7 +192,7 @@ export class BufferLine implements IBufferLine { } this._data = data; for (let i = this.length; i < cols; ++i) { - this.set(i, fill); + this.set(i, fillCharData); } } else if (shrink) { if (cols) {