Skip to content

Commit 33bf765

Browse files
authored
Merge pull request #3067 from mmis1000/fix/addon-serialize-cjk-handling
Fix cjk handling in SerializeAddon
2 parents d960793 + 0fb6356 commit 33bf765

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

addons/xterm-addon-serialize/src/SerializeAddon.api.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,35 @@ describe('SerializeAddon', () => {
270270
await writeSync(page, lines.join('\\r\\n'));
271271
assert.equal(await page.evaluate(`serializeAddon.serialize();`), expected.join('\r\n'));
272272
});
273+
274+
it('serialize CJK correctly', async () => {
275+
const lines = [
276+
'中文中文',
277+
'12中文',
278+
'中文12',
279+
'1中文中文中' // this line is going to be wrapped at last character because it has line length of 11 (1+2*5)
280+
];
281+
const expected = [
282+
'中文中文',
283+
'12中文',
284+
'中文12',
285+
'1中文中文',
286+
'中'
287+
];
288+
await writeSync(page, lines.join('\\r\\n'));
289+
assert.equal(await page.evaluate(`serializeAddon.serialize();`), expected.join('\r\n'));
290+
});
291+
292+
it('serialize CJK Mixed with tab correctly', async () => {
293+
const lines = [
294+
'中文\t12' // CJK mixed with tab
295+
];
296+
const expected = [
297+
'中文\x1b[4C12'
298+
];
299+
await writeSync(page, lines.join('\\r\\n'));
300+
assert.equal(await page.evaluate(`serializeAddon.serialize();`), expected.join('\r\n'));
301+
});
273302
});
274303

275304
function newArray<T>(initial: T | ((index: number) => T), count: number): T[] {

addons/xterm-addon-serialize/src/SerializeAddon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
138138
// Count number of null cells encountered after the last non-null cell and move the cursor
139139
// if a non-null cell is found (eg. \t or cursor move)
140140
if (cell.getChars() === '') {
141-
this._nullCellCount++;
141+
this._nullCellCount += cell.getWidth();
142142
} else if (this._nullCellCount > 0) {
143143
this._currentRow += `\x1b[${this._nullCellCount}C`;
144144
this._nullCellCount = 0;

0 commit comments

Comments
 (0)