mirror of
https://github.com/signynt/virtual-content.git
synced 2026-07-22 05:46:44 +00:00
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:
commit
24c5040bbb
1 changed files with 11 additions and 0 deletions
11
main.ts
11
main.ts
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue