Open internal links in new tab on ctrl/meta clicks

This commit is contained in:
aNNiMON 2025-12-19 21:40:54 +02:00
parent fdcce0223a
commit 2448fe82ad

View file

@ -24,9 +24,22 @@ export class InternalLinkProcessor implements DOMProcessor {
if (!href) return;
link.addEventListener("click", (e) => {
e.preventDefault();
this.app.workspace.openLinkText(href, ctx.sourcePath);
const newTab = this.shouldOpenInNewTab(e);
this.app.workspace.openLinkText(href, ctx.sourcePath, newTab);
});
});
return element;
}
private shouldOpenInNewTab(e: Event): boolean {
if (
e instanceof PointerEvent ||
e instanceof MouseEvent ||
e instanceof TouchEvent ||
e instanceof KeyboardEvent
) {
return (e.ctrlKey || e.metaKey);
}
return false;
}
}