@@ -9,16 +9,18 @@ export class LinkProvider implements ILinkProvider {
99 * @param _regex The regular expression to use for matching
1010 * @param _handler Callback for when link is clicked
1111 * @param _options Further hooks, eg. hover, leave and decorations
12+ * @param _matchIndex The index to use from regexp.exec result, default 1
1213 */
1314 constructor (
1415 private readonly _terminal : Terminal ,
1516 private readonly _regex : RegExp ,
1617 private readonly _handler : ILink [ 'activate' ] ,
17- private readonly _options : ILinkProviderOptions = { }
18+ private readonly _options : ILinkProviderOptions = { } ,
19+ private readonly _matchIndex = 1
1820 ) { }
1921
2022 public provideLinks ( y : number , callback : ( links : ILink [ ] | undefined ) => void ) : void {
21- const links = computeLink ( y , this . _regex , this . _terminal ) . map (
23+ const links = computeLink ( y , this . _regex , this . _terminal , this . _matchIndex ) . map (
2224 ( _link ) : ILink => ( {
2325 range : _link . range ,
2426 text : _link . text ,
@@ -34,8 +36,9 @@ export class LinkProvider implements ILinkProvider {
3436 * @param y The line number to process
3537 * @param regex The regular expression to use for matching
3638 * @param terminal The terminal instance
39+ * @param matchIndex The index to use from regexp.exec result, default 1
3740 */
38- export const computeLink = ( y : number , regex : RegExp , terminal : Terminal ) => {
41+ export const computeLink = ( y : number , regex : RegExp , terminal : Terminal , matchIndex = 1 ) => {
3942 const rex = new RegExp (
4043 regex . source ,
4144 ( ( regex . flags || '' ) + 'g' )
@@ -51,7 +54,7 @@ export const computeLink = (y: number, regex: RegExp, terminal: Terminal) => {
5154 const result : Pick < ILink , 'range' | 'text' > [ ] = [ ] ;
5255
5356 while ( ( match = rex . exec ( line ) ) !== null ) {
54- const text = match [ 1 ] ;
57+ const text = match [ matchIndex ] ;
5558 if ( ! text ) {
5659 // something matched but does not comply with the given matchIndex
5760 // since this is most likely a bug the regex itself we simply do nothing here
0 commit comments