Skip to content

Commit 963f49d

Browse files
authored
Revert "Treat commas as link terminators (microsoft#168752)" (microsoft#174847)
Revert "Treat commas as link terminators (microsoft#168752)" to fix microsoft#174009 This reverts commit f730897.
1 parent 59f6d52 commit 963f49d

File tree

2 files changed

+34
-36
lines changed

2 files changed

+34
-36
lines changed

src/vs/editor/common/languages/linkComputer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ function getClassifier(): CharacterClassifier<CharacterClass> {
155155
_classifier = new CharacterClassifier<CharacterClass>(CharacterClass.None);
156156

157157
// allow-any-unicode-next-line
158-
const FORCE_TERMINATION_CHARACTERS = ', \t<>\'\"、。。、,.:;‘〈「『〔([{「」}])〕』」〉’`~…';
158+
const FORCE_TERMINATION_CHARACTERS = ' \t<>\'\"、。。、,.:;‘〈「『〔([{「」}])〕』」〉’`~…';
159159
for (let i = 0; i < FORCE_TERMINATION_CHARACTERS.length; i++) {
160160
_classifier.set(FORCE_TERMINATION_CHARACTERS.charCodeAt(i), CharacterClass.ForceTermination);
161161
}
162162

163-
const CANNOT_END_WITH_CHARACTERS = '.;:';
163+
const CANNOT_END_WITH_CHARACTERS = '.,;:';
164164
for (let i = 0; i < CANNOT_END_WITH_CHARACTERS.length; i++) {
165165
_classifier.set(CANNOT_END_WITH_CHARACTERS.charCodeAt(i), CharacterClass.CannotEndIn);
166166
}

src/vs/editor/test/common/modes/linkComputer.test.ts

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,38 @@ function myComputeLinks(lines: string[]): ILink[] {
2626
return computeLinks(target);
2727
}
2828

29-
function extractLinks(text: string): string {
30-
const keep: boolean[] = [];
31-
const links = myComputeLinks([text]);
32-
for (const link of links) {
33-
const startChar = link.range.startColumn - 1;
34-
const endChar = link.range.endColumn - 1;
35-
for (let char = startChar; char < endChar; char++) {
36-
keep[char] = true;
29+
function assertLink(text: string, extractedLink: string): void {
30+
let startColumn = 0,
31+
endColumn = 0,
32+
chr: string,
33+
i = 0;
34+
35+
for (i = 0; i < extractedLink.length; i++) {
36+
chr = extractedLink.charAt(i);
37+
if (chr !== ' ' && chr !== '\t') {
38+
startColumn = i + 1;
39+
break;
3740
}
3841
}
39-
const result: string[] = [];
40-
for (let i = 0; i < text.length; i++) {
41-
if (keep[i]) {
42-
result.push(text.charAt(i));
43-
} else {
44-
result.push(' ');
42+
43+
for (i = extractedLink.length - 1; i >= 0; i--) {
44+
chr = extractedLink.charAt(i);
45+
if (chr !== ' ' && chr !== '\t') {
46+
endColumn = i + 2;
47+
break;
4548
}
4649
}
47-
return result.join('');
48-
}
4950

50-
function assertLink(text: string, expectedLinks: string): void {
51-
assert.deepStrictEqual(extractLinks(text), expectedLinks);
51+
const r = myComputeLinks([text]);
52+
assert.deepStrictEqual(r, [{
53+
range: {
54+
startLineNumber: 1,
55+
startColumn: startColumn,
56+
endLineNumber: 1,
57+
endColumn: endColumn
58+
},
59+
url: extractedLink.substring(startColumn - 1, endColumn - 1)
60+
}]);
5261
}
5362

5463
suite('Editor Modes - Link Computer', () => {
@@ -97,19 +106,19 @@ suite('Editor Modes - Link Computer', () => {
97106

98107
assertLink(
99108
'(see http://foo.bar)',
100-
' http://foo.bar '
109+
' http://foo.bar '
101110
);
102111
assertLink(
103112
'[see http://foo.bar]',
104-
' http://foo.bar '
113+
' http://foo.bar '
105114
);
106115
assertLink(
107116
'{see http://foo.bar}',
108-
' http://foo.bar '
117+
' http://foo.bar '
109118
);
110119
assertLink(
111120
'<see http://foo.bar>',
112-
' http://foo.bar '
121+
' http://foo.bar '
113122
);
114123
assertLink(
115124
'<url>http://mylink.com</url>',
@@ -190,7 +199,7 @@ suite('Editor Modes - Link Computer', () => {
190199
test('issue #62278: "Ctrl + click to follow link" for IPv6 URLs', () => {
191200
assertLink(
192201
'let x = "http://[::1]:5000/connect/token"',
193-
' http://[::1]:5000/connect/token '
202+
' http://[::1]:5000/connect/token '
194203
);
195204
});
196205

@@ -264,15 +273,4 @@ suite('Editor Modes - Link Computer', () => {
264273
` https://github.com/jeff-hykin/better-c-syntax/blob/master/autogenerated/c.tmLanguage.json `,
265274
);
266275
});
267-
268-
test('issue #119696: Links shouldn\'t include commas', () => {
269-
assertLink(
270-
`https://apod.nasa.gov/apod/ap170720.html,IC 1396: Emission Nebula in Cepheus,https://apod.nasa.gov/apod/image/1707/MOSAIC_IC1396_HaSHO_blanco1024.jpg,https://apod.nasa.gov/apod/image/1707/MOSAIC_IC1396_HaSHO_blanco.jpg`,
271-
`https://apod.nasa.gov/apod/ap170720.html https://apod.nasa.gov/apod/image/1707/MOSAIC_IC1396_HaSHO_blanco1024.jpg https://apod.nasa.gov/apod/image/1707/MOSAIC_IC1396_HaSHO_blanco.jpg`
272-
);
273-
assertLink(
274-
`https://apod.nasa.gov/apod/ap180402.html,"Moons, Rings, Shadows, Clouds: Saturn (Cassini)",https://apod.nasa.gov/apod/image/1804/SaturnRingsMoons_Cassini_967.jpg,https://apod.nasa.gov/apod/image/1804/SaturnRingsMoons_Cassini_967.jpg`,
275-
`https://apod.nasa.gov/apod/ap180402.html https://apod.nasa.gov/apod/image/1804/SaturnRingsMoons_Cassini_967.jpg https://apod.nasa.gov/apod/image/1804/SaturnRingsMoons_Cassini_967.jpg`,
276-
);
277-
});
278276
});

0 commit comments

Comments
 (0)