Skip to content

Commit d2083c5

Browse files
authored
Merge pull request #3835 from Tyriar/3834
Fix search when the search line contains a null character
2 parents cd975d2 + 0c0a34d commit d2083c5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

addons/xterm-addon-search/src/SearchAddon.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ export class SearchAddon implements ITerminalAddon {
610610
break;
611611
}
612612
if (cell.getWidth()) {
613-
offset += cell.getChars().length;
613+
// Treat null characters as whitespace to align with the translateToString API
614+
offset += cell.getCode() === 0 ? 1 : cell.getChars().length;
614615
}
615616
}
616617
lineIndex++;

addons/xterm-addon-search/test/SearchAddon.api.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,21 @@ describe('Search Tests', function(): void {
379379
});
380380
});
381381
});
382+
describe('#3834 lines with null characters before search terms', () => {
383+
// This case can be triggered by the prompt when using starship under conpty
384+
it('should find all matches on a line containing null characters', async () => {
385+
await page.evaluate(`
386+
window.calls = [];
387+
window.search.onDidChangeResults(e => window.calls.push(e));
388+
`);
389+
// Move cursor forward 1 time to create a null character, as opposed to regular whitespace
390+
await writeSync(page, '\\x1b[CHi Hi');
391+
assert.strictEqual(await page.evaluate(`window.search.findPrevious('h', { decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), true);
392+
assert.deepStrictEqual(await page.evaluate('window.calls'), [
393+
{ resultCount: 2, resultIndex: 1 }
394+
]);
395+
});
396+
});
382397
});
383398

384399
function makeData(length: number): string {

0 commit comments

Comments
 (0)