mirror of
https://github.com/James-Yu/LaTeX-Workshop.git
synced 2024-10-04 15:17:59 +03:00
Handle external links in the embedded viewer
This commit is contained in:
parent
965d03970e
commit
309f82ce8d
@ -152,6 +152,9 @@ export class Viewer {
|
||||
case 'click':
|
||||
this.extension.locator.locate(data, decodeURIComponent(data.path))
|
||||
break
|
||||
case 'external_link':
|
||||
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(data.url))
|
||||
break
|
||||
default:
|
||||
this.extension.logger.addLogMessage(`Unknown websocket message: ${msg}`)
|
||||
break
|
||||
|
@ -420,6 +420,16 @@ See https://github.com/adobe-type-tools/cmap-resources
|
||||
socket.send(JSON.stringify({type:"loaded", path:file}))
|
||||
})
|
||||
|
||||
// if we're embedded we cannot open external links here. So we intercept clicks and forward them to the extension
|
||||
if (window.parent !== window) {
|
||||
document.addEventListener('click', (e) => {
|
||||
if (e.target.nodeName == 'A' && !e.target.href.startsWith(window.location.href)) { // is external link
|
||||
socket.send(JSON.stringify({type:"external_link", url:e.target.href}))
|
||||
e.preventDefault();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
document.addEventListener('pagerendered', (e) => {
|
||||
let page = e.target.dataset.pageNumber
|
||||
let target = e.target
|
||||
|
Loading…
Reference in New Issue
Block a user