diff --git a/addons/addon-serialize/src/SerializeAddon.ts b/addons/addon-serialize/src/SerializeAddon.ts index e1728feb21..c8a1c72fd2 100644 --- a/addons/addon-serialize/src/SerializeAddon.ts +++ b/addons/addon-serialize/src/SerializeAddon.ts @@ -250,10 +250,16 @@ class StringSerializeHandler extends BaseSerializeHandler { if (this._nullCellCount > 0) { // do these because we filled the last several null slot, which we shouldn't + // a move of 0 means a move of 1, so skip the moves when the row has no content + const contentLength = currentLine.length - this._nullCellCount; rowSeparator += '\u001b[A'; - rowSeparator += `\u001b[${currentLine.length - this._nullCellCount}C`; + if (contentLength > 0) { + rowSeparator += `\u001b[${contentLength}C`; + } rowSeparator += `\u001b[${this._nullCellCount}X`; - rowSeparator += `\u001b[${currentLine.length - this._nullCellCount}D`; + if (contentLength > 0) { + rowSeparator += `\u001b[${contentLength}D`; + } rowSeparator += '\u001b[B'; } diff --git a/addons/addon-serialize/test/SerializeAddon.test.ts b/addons/addon-serialize/test/SerializeAddon.test.ts index f84452d58b..21a24e9122 100644 --- a/addons/addon-serialize/test/SerializeAddon.test.ts +++ b/addons/addon-serialize/test/SerializeAddon.test.ts @@ -520,6 +520,22 @@ test.describe('SerializeAddon', () => { await testNormalScreenEqual(ctx.page, segments.join('')); }); + test('handle empty row followed by wrapped row', async () => { + const CLEAR_RIGHT = (l: number): string => `\u001b[${l}X`; + const MOVE_TO = (row: number, col: number): string => `\u001b[${row};${col}H`; + + // The wrap is forced with a row of dashes. With no content in the row, the + // moves around the erase have a count of 0, which means 1. + const segments = [ + 'abcdefghijXYZ', + MOVE_TO(1, 1), + CLEAR_RIGHT(10), + MOVE_TO(2, 4) + ]; + + await testNormalScreenEqual(ctx.page, segments.join('')); + }); + test('handle invalid wrap after scroll', async () => { const CLEAR_RIGHT = (l: number): string => `\u001b[${l}X`; const MOVE_UP = (l: number): string => `\u001b[${l}A`;