fixed linkifier plugin not working with multiple providers

This commit is contained in:
Eugene Pankov 2022-10-25 19:29:25 +02:00
parent 07b0aa3d70
commit a29a552afc
No known key found for this signature in database
GPG key ID: 5896FCBBDD1CF4F4

View file

@ -29,28 +29,43 @@ export class LinkHighlighterDecorator extends TerminalDecorator {
}, },
} }
const openLink = async uri => {
for (const handler of this.handlers) { for (const handler of this.handlers) {
const getLink = async uri => handler.convert(uri, tab) if (!handler.regex.test(uri)) {
const openLink = async uri => handler.handle(await getLink(uri), tab) continue
}
if (!await handler.verify(await handler.convert(uri, tab), tab)) {
continue
}
handler.handle(await handler.convert(uri, tab), tab)
}
}
let regex = new RegExp('')
const regexSource = this.handlers.map(x => `(${x.regex.source})`).join('|')
try {
regex = new RegExp(regexSource)
console.debug('Linkifier regexp', regex)
} catch (error) {
console.error('Could not build regex for your link handlers:', error)
console.error('Regex source was:', regexSource)
return
}
const addon = new WebLinksAddon( const addon = new WebLinksAddon(
async (event, uri) => { async (event, uri) => {
if (!this.willHandleEvent(event)) { if (!this.willHandleEvent(event)) {
return return
} }
if (!await handler.verify(await handler.convert(uri, tab), tab)) {
return
}
openLink(uri) openLink(uri)
}, },
{ {
urlRegex: handler.regex, urlRegex: regex,
}, },
) )
tab.frontend.xterm.loadAddon(addon) tab.frontend.xterm.loadAddon(addon)
} }
}
private willHandleEvent (event: MouseEvent) { private willHandleEvent (event: MouseEvent) {
const modifier = this.config.store.clickableLinks.modifier const modifier = this.config.store.clickableLinks.modifier