Merge pull request #54 from aaandreeew/main

Fixes to ctrl+click and middle-click behaviour of links in virtual content
This commit is contained in:
Vincenzo Mitchell Barroso 2026-05-08 16:36:21 +02:00 committed by GitHub
commit 24c5040bbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

11
main.ts
View file

@ -1752,6 +1752,9 @@ export default class VirtualFooterPlugin extends Plugin {
* @param component The Obsidian Component associated with this content, for event registration.
*/
public attachInternalLinkHandlers(container: HTMLElement, sourcePath: string, component: Component): void {
// If in reading view, do nothing, as the default behavior is fine
if (container.closest(".markdown-reading-view")) return;
// Handle left-click on internal links and external file links
component.registerDomEvent(container, 'click', (event: MouseEvent) => {
if (event.button !== 0) return; // Only handle left-clicks
@ -1787,6 +1790,14 @@ export default class VirtualFooterPlugin extends Plugin {
if (href) {
this.app.workspace.openLinkText(href, sourcePath, true); // Always open in new pane for middle-click
}
return;
}
// Handle external file links which don't work natively in Live Preview injected content
const externalLink = target.closest('a.external-link') as HTMLAnchorElement;
if (externalLink && externalLink.href.startsWith('file:')) {
event.preventDefault();
window.open(externalLink.href);
}
});
}