File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,20 +15,32 @@ var URIMatcher = {
1515 if ( match . length == 0 )
1616 return null ;
1717
18+ const longestResultAt = new Map ( ) ;
1819 for ( let maybeURI of match ) {
1920 maybeURI = this . sanitizeURIString ( maybeURI ) ;
2021 const uriRange = await this . findTextRange ( {
2122 text : maybeURI ,
2223 range : params . cursor ,
2324 tabId : params . tabId
2425 } ) ;
25- if ( ! uriRange )
26+ if ( ! uriRange ) {
2627 continue ;
27- return {
28+ }
29+ const positionKey = `${ uriRange . startTextNodePos } :${ uriRange . startOffset } ` ;
30+ const result = {
2831 text : maybeURI ,
2932 range : uriRange ,
3033 uri : this . fixupURI ( maybeURI , params . baseURI )
3134 } ;
35+ const longestResult = longestResultAt . get ( positionKey ) ;
36+ if ( ! longestResult ||
37+ ( longestResult . text . length <= maybeURI . length &&
38+ maybeURI . startsWith ( longestResult . text ) ) ) {
39+ longestResultAt . set ( positionKey , result ) ;
40+ }
41+ }
42+ if ( longestResultAt . size > 0 ) {
43+ return [ ...longestResultAt . values ( ) ] [ 0 ] ;
3244 }
3345 log ( ' => no match' ) ;
3446 }
You can’t perform that action at this time.
0 commit comments