Skip to content

Commit

Permalink
Support wide character word links
Browse files Browse the repository at this point in the history
Fixes #96416
  • Loading branch information
Tyriar committed Apr 29, 2020
1 parent 669b0da commit d2e4fab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ITerminalConfiguration>(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;
}

Expand All @@ -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<ITerminalConfiguration>(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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});
});

0 comments on commit d2e4fab

Please sign in to comment.