Revert "Stop opening external links."

This reverts commit a4f6c38e27.
This commit is contained in:
James-Yu 2022-10-17 10:17:46 +08:00
parent b18f844089
commit 5ba3f10e1a
3 changed files with 9 additions and 0 deletions

View File

@ -259,6 +259,10 @@ export class Viewer implements IViewer {
void this.extension.locator.locate(data, uri.fsPath)
break
}
case 'external_link': {
void vscode.env.openExternal(vscode.Uri.parse(data.url))
break
}
case 'ping': {
// nothing to do
break

View File

@ -49,6 +49,9 @@ export type ClientRequest = {
} | {
type: 'loaded',
pdfFileUri: string
} | {
type: 'external_link',
url: string
} | {
type: 'ping'
} | {

View File

@ -490,10 +490,12 @@ class LateXWorkshopPdfViewer implements ILatexWorkshopPdfViewer {
}
private registerKeybinding() {
// if we're embedded we cannot open external links here. So we intercept clicks and forward them to the extension
if (this.embedded) {
document.addEventListener('click', (e) => {
const target = e.target as HTMLAnchorElement
if (target.nodeName === 'A' && !target.href.startsWith(window.location.href) && !target.href.startsWith('blob:')) { // is external link
this.send({type:'external_link', url:target.href})
e.preventDefault()
}
})