@@ -157,23 +157,6 @@ function equalFlags(cell1: IBufferCell, cell2: IBufferCell): boolean { |
157 | 157 | abstract class BaseSerializeHandler { |
158 | 158 | constructor(protected readonly _buffer: IBuffer) {} |
159 | 159 |
|
160 | | - private _isRealContent(codepoint: number): boolean { |
161 | | - if (codepoint === 0) return false |
162 | | - if (codepoint >= 0xf000) return false |
163 | | - return true |
164 | | - } |
165 | | - |
166 | | - private _findLastContentColumn(line: IBufferLine): number { |
167 | | - let lastContent = -1 |
168 | | - for (let col = 0; col < line.length; col++) { |
169 | | - const cell = line.getCell(col) |
170 | | - if (cell && this._isRealContent(cell.getCode())) { |
171 | | - lastContent = col |
172 | | - } |
173 | | - } |
174 | | - return lastContent + 1 |
175 | | - } |
176 | | - |
177 | 160 | public serialize(range: IBufferRange, excludeFinalCursorPosition?: boolean): string { |
178 | 161 | let oldCell = this._buffer.getNullCell() |
179 | 162 |
|
@@ -182,14 +165,14 @@ abstract class BaseSerializeHandler { |
182 | 165 | const startColumn = range.start.x |
183 | 166 | const endColumn = range.end.x |
184 | 167 |
|
185 | | - this._beforeSerialize(endRow - startRow, startRow, endRow) |
| 168 | + this._beforeSerialize(endRow - startRow + 1, startRow, endRow) |
186 | 169 |
|
187 | 170 | for (let row = startRow; row <= endRow; row++) { |
188 | 171 | const line = this._buffer.getLine(row) |
189 | 172 | if (line) { |
190 | 173 | const startLineColumn = row === range.start.y ? startColumn : 0 |
191 | | - const maxColumn = row === range.end.y ? endColumn : this._findLastContentColumn(line) |
192 | | - const endLineColumn = Math.min(maxColumn, line.length) |
| 174 | + const endLineColumn = Math.min(endColumn, line.length) |
| 175 | + |
193 | 176 | for (let col = startLineColumn; col < endLineColumn; col++) { |
194 | 177 | const c = line.getCell(col) |
195 | 178 | if (!c) { |
@@ -243,6 +226,13 @@ class StringSerializeHandler extends BaseSerializeHandler { |
243 | 226 |
|
244 | 227 | protected _beforeSerialize(rows: number, start: number, _end: number): void { |
245 | 228 | this._allRows = new Array<string>(rows) |
| 229 | + this._allRowSeparators = new Array<string>(rows) |
| 230 | + this._rowIndex = 0 |
| 231 | + |
| 232 | + this._currentRow = "" |
| 233 | + this._nullCellCount = 0 |
| 234 | + this._cursorStyle = this._buffer.getNullCell() |
| 235 | + |
246 | 236 | this._lastContentCursorRow = start |
247 | 237 | this._lastCursorRow = start |
248 | 238 | this._firstRow = start |
@@ -251,6 +241,11 @@ class StringSerializeHandler extends BaseSerializeHandler { |
251 | 241 | protected _rowEnd(row: number, isLastRow: boolean): void { |
252 | 242 | let rowSeparator = "" |
253 | 243 |
|
| 244 | + if (this._nullCellCount > 0) { |
| 245 | + this._currentRow += " ".repeat(this._nullCellCount) |
| 246 | + this._nullCellCount = 0 |
| 247 | + } |
| 248 | + |
254 | 249 | if (!isLastRow) { |
255 | 250 | const nextLine = this._buffer.getLine(row + 1) |
256 | 251 |
|
@@ -388,7 +383,8 @@ class StringSerializeHandler extends BaseSerializeHandler { |
388 | 383 | } |
389 | 384 |
|
390 | 385 | const codepoint = cell.getCode() |
391 | | - const isGarbage = codepoint >= 0xf000 |
| 386 | + const isInvalidCodepoint = codepoint > 0x10ffff || (codepoint >= 0xd800 && codepoint <= 0xdfff) |
| 387 | + const isGarbage = isInvalidCodepoint || (codepoint >= 0xf000 && cell.getWidth() === 1) |
392 | 388 | const isEmptyCell = codepoint === 0 || cell.getChars() === "" || isGarbage |
393 | 389 |
|
394 | 390 | const sgrSeq = this._diffStyle(cell, this._cursorStyle) |
@@ -397,7 +393,7 @@ class StringSerializeHandler extends BaseSerializeHandler { |
397 | 393 |
|
398 | 394 | if (styleChanged) { |
399 | 395 | if (this._nullCellCount > 0) { |
400 | | - this._currentRow += `\u001b[${this._nullCellCount}C` |
| 396 | + this._currentRow += " ".repeat(this._nullCellCount) |
401 | 397 | this._nullCellCount = 0 |
402 | 398 | } |
403 | 399 |
|
@@ -417,7 +413,7 @@ class StringSerializeHandler extends BaseSerializeHandler { |
417 | 413 | this._nullCellCount += cell.getWidth() |
418 | 414 | } else { |
419 | 415 | if (this._nullCellCount > 0) { |
420 | | - this._currentRow += `\u001b[${this._nullCellCount}C` |
| 416 | + this._currentRow += " ".repeat(this._nullCellCount) |
421 | 417 | this._nullCellCount = 0 |
422 | 418 | } |
423 | 419 |
|
|