diff --git a/src/vs/workbench/contrib/terminal/browser/links/terminalWordLinkProvider.ts b/src/vs/workbench/contrib/terminal/browser/links/terminalWordLinkProvider.ts index c6b4b85bbd07c864b10910624b27cd89c4d5f85d..84d7b9a29f52f4b6f7c50ee5dea54a0d029f96c2 100644 --- a/src/vs/workbench/contrib/terminal/browser/links/terminalWordLinkProvider.ts +++ b/src/vs/workbench/contrib/terminal/browser/links/terminalWordLinkProvider.ts @@ -37,21 +37,21 @@ export class TerminalWordLinkProvider implements ILinkProvider { const end: IBufferCellPosition = { x: position.x, y: position.y }; // TODO: Support wrapping - // Expand to the left until a word separator is hit const line = this._xterm.buffer.active.getLine(position.y - 1)!; let text = ''; start.x++; // The hovered cell is considered first for (let x = position.x; x > 0; x--) { - const char = line.getCell(x - 1)?.getChars(); - if (!char) { + const cell = line.getCell(x - 1); + if (!cell) { break; } + const char = cell.getChars(); const config = this._configurationService.getValue(TERMINAL_CONFIG_SECTION); - if (config.wordSeparators.indexOf(char) >= 0) { + if (cell.getWidth() !== 0 && config.wordSeparators.indexOf(char) >= 0) { break; } - start.x--; + start.x = x; text = char + text; } @@ -62,17 +62,17 @@ export class TerminalWordLinkProvider implements ILinkProvider { } // Expand to the right until a word separator is hit - // end.x++; // The hovered cell is considered first for (let x = position.x + 1; x <= line.length; x++) { - const char = line.getCell(x - 1)?.getChars(); - if (!char) { + const cell = line.getCell(x - 1); + if (!cell) { break; } + const char = cell.getChars(); const config = this._configurationService.getValue(TERMINAL_CONFIG_SECTION); - if (config.wordSeparators.indexOf(char) >= 0) { + if (cell.getWidth() !== 0 && config.wordSeparators.indexOf(char) >= 0) { break; } - end.x++; + end.x = x; text += char; } diff --git a/src/vs/workbench/contrib/terminal/test/browser/links/terminalWordLinkProvider.test.ts b/src/vs/workbench/contrib/terminal/test/browser/links/terminalWordLinkProvider.test.ts index 89dfb339cdaea9d40e9bb00944dbfe048a32b9b2..cce6ad538ea8b1a2cd10bfdd2aec1bedaf3bde71 100644 --- a/src/vs/workbench/contrib/terminal/test/browser/links/terminalWordLinkProvider.test.ts +++ b/src/vs/workbench/contrib/terminal/test/browser/links/terminalWordLinkProvider.test.ts @@ -75,4 +75,14 @@ suite('Workbench - TerminalWordLinkProvider', () => { await assertLink('[foo]', { range: [[1, 1], [5, 1]], text: '[foo]' }); await assertLink('{foo}', { range: [[1, 1], [5, 1]], text: '{foo}' }); }); + + test('should support wide characters', async () => { + await configurationService.setUserConfiguration('terminal', { integrated: { wordSeparators: ' []' } }); + await assertLink('aabbccdd.txt ', { range: [[1, 1], [12, 1]], text: 'aabbccdd.txt' }); + await assertLink('我是学生.txt ', { range: [[1, 1], [12, 1]], text: '我是学生.txt' }); + await assertLink(' aabbccdd.txt ', { range: [[2, 1], [13, 1]], text: 'aabbccdd.txt' }); + await assertLink(' 我是学生.txt ', { range: [[2, 1], [13, 1]], text: '我是学生.txt' }); + await assertLink(' [aabbccdd.txt] ', { range: [[3, 1], [14, 1]], text: 'aabbccdd.txt' }); + await assertLink(' [我是学生.txt] ', { range: [[3, 1], [14, 1]], text: '我是学生.txt' }); + }); });