From 9c8deb14705435377aa243ae6db041e608aa540e Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 4 Feb 2020 08:36:57 -0800 Subject: [PATCH] Revert "Remove getNullCell" This reverts commit 0b6a5b763095f516dd88453844a5743fffe0cfbc. --- .../src/SerializeAddon.ts | 20 +++---------------- src/public/Terminal.ts | 1 + typings/xterm.d.ts | 7 +++++++ 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/addons/xterm-addon-serialize/src/SerializeAddon.ts b/addons/xterm-addon-serialize/src/SerializeAddon.ts index 94a3b7ce..1d011726 100644 --- a/addons/xterm-addon-serialize/src/SerializeAddon.ts +++ b/addons/xterm-addon-serialize/src/SerializeAddon.ts @@ -16,7 +16,9 @@ abstract class BaseSerializeHandler { constructor(private _buffer: IBuffer) { } serialize(startRow: number, endRow: number): string { - const { cell1, cell2 } = this._getWorkCells(); + // we need two of them to flip between old and new cell + const cell1 = this._buffer.getNullCell(); + const cell2 = this._buffer.getNullCell(); let oldCell = cell1; this._beforeSerialize(endRow - startRow); @@ -42,22 +44,6 @@ abstract class BaseSerializeHandler { return this._serializeString(); } - private _getWorkCells(): { cell1: IBufferCell, cell2: IBufferCell } { - const line = this._buffer.getLine(0); - if (!line) { - throw new Error('Could not fetch first line for serialization'); - } - const cell1 = line.getCell(0); - if (!cell1) { - throw new Error('Could not fetch first cell for serialization'); - } - const cell2 = line.getCell(0); - if (!cell2) { - throw new Error('Could not fetch first cell for serialization'); - } - return { cell1, cell2 }; - } - protected _nextCell(cell: IBufferCell, oldCell: IBufferCell, row: number, col: number): void { } protected _rowEnd(row: number): void { } protected _beforeSerialize(rows: number): void { } diff --git a/src/public/Terminal.ts b/src/public/Terminal.ts index 2b180a4a..065dfb64 100644 --- a/src/public/Terminal.ts +++ b/src/public/Terminal.ts @@ -204,6 +204,7 @@ class BufferApiView implements IBufferApi { } return new BufferLineApiView(line); } + public getNullCell(): IBufferCellApi { return new CellData(); } } class BufferLineApiView implements IBufferLineApi { diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 2685d55c..7b430722 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -1117,6 +1117,13 @@ declare module 'xterm' { * @param y The line index to get. */ getLine(y: number): IBufferLine | undefined; + + /** + * Creates an empty cell object suitable as a cell reference in + * `line.getCell(x, cell)`. Use this to avoid costly recreation of + * cell objects when dealing with tons of cells. + */ + getNullCell(): IBufferCell; } /**