@@ -26,29 +26,38 @@ function myComputeLinks(lines: string[]): ILink[] {
26
26
return computeLinks ( target ) ;
27
27
}
28
28
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 ;
37
40
}
38
41
}
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 ;
45
48
}
46
49
}
47
- return result . join ( '' ) ;
48
- }
49
50
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
+ } ] ) ;
52
61
}
53
62
54
63
suite ( 'Editor Modes - Link Computer' , ( ) => {
@@ -97,19 +106,19 @@ suite('Editor Modes - Link Computer', () => {
97
106
98
107
assertLink (
99
108
'(see http://foo.bar)' ,
100
- ' http://foo.bar '
109
+ ' http://foo.bar '
101
110
) ;
102
111
assertLink (
103
112
'[see http://foo.bar]' ,
104
- ' http://foo.bar '
113
+ ' http://foo.bar '
105
114
) ;
106
115
assertLink (
107
116
'{see http://foo.bar}' ,
108
- ' http://foo.bar '
117
+ ' http://foo.bar '
109
118
) ;
110
119
assertLink (
111
120
'<see http://foo.bar>' ,
112
- ' http://foo.bar '
121
+ ' http://foo.bar '
113
122
) ;
114
123
assertLink (
115
124
'<url>http://mylink.com</url>' ,
@@ -190,7 +199,7 @@ suite('Editor Modes - Link Computer', () => {
190
199
test ( 'issue #62278: "Ctrl + click to follow link" for IPv6 URLs' , ( ) => {
191
200
assertLink (
192
201
'let x = "http://[::1]:5000/connect/token"' ,
193
- ' http://[::1]:5000/connect/token '
202
+ ' http://[::1]:5000/connect/token '
194
203
) ;
195
204
} ) ;
196
205
@@ -264,15 +273,4 @@ suite('Editor Modes - Link Computer', () => {
264
273
` https://github.com/jeff-hykin/better-c-syntax/blob/master/autogenerated/c.tmLanguage.json ` ,
265
274
) ;
266
275
} ) ;
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
- } ) ;
278
276
} ) ;
0 commit comments