Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
use shell.openExternal for URI protocol handling, clean up and unify logic
laundf709c27329d0
diff --git a/apps/client/src/services/link.ts b/apps/client/src/services/link.tsindex a583ea65ba..e26e821e6d 100644--- a/apps/client/src/services/link.ts+++ b/apps/client/src/services/link.ts@@ -302,7 +302,8 @@ export function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDo// Right click is handled separately.const isMiddleClick = evt && "which" in evt && evt.which === 2;const targetIsBlank = ($link?.attr("target") === "_blank");- const openInNewTab = (isLeftClick && ctrlKey) || isMiddleClick || targetIsBlank;+ const isDoubleClick = isLeftClick && evt?.type === "dblclick";+ const openInNewTab = (isLeftClick && ctrlKey) || isDoubleClick || isMiddleClick || targetIsBlank;const activate = (isLeftClick && ctrlKey && shiftKey) || (isMiddleClick && shiftKey);const openInNewWindow = isLeftClick && evt?.shiftKey && !ctrlKey;@@ -323,16 +324,18 @@ export function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDoconst withinEditLink = $link?.hasClass("ck-link-actions__preview");const outsideOfCKEditor = !$link || $link.closest("[contenteditable]").length === 0;- if (openInNewTab || (withinEditLink && (isLeftClick || isMiddleClick)) || (outsideOfCKEditor && (isLeftClick || isMiddleClick))) {+ if (openInNewTab || openInNewWindow || (isLeftClick && (withinEditLink || outsideOfCKEditor))) {if (hrefLink.toLowerCase().startsWith("http") || hrefLink.startsWith("api/")) {window.open(hrefLink, "_blank");- } else if ((hrefLink.toLowerCase().startsWith("file:") || hrefLink.toLowerCase().startsWith("geo:")) && utils.isElectron()) {- const electron = utils.dynamicRequire("electron");- electron.shell.openPath(hrefLink);} else {// Enable protocols supported by CKEditor 5 to be clickable.if (ALLOWED_PROTOCOLS.some((protocol) => hrefLink.toLowerCase().startsWith(protocol + ":"))) {- window.open(hrefLink, "_blank");+ if ( utils.isElectron()) {+ const electron = utils.dynamicRequire("electron");+ electron.shell.openExternal(hrefLink);+ } else {+ window.open(hrefLink, "_blank");+ }}}}@@ -468,18 +471,9 @@ $(document).on("auxclick", "a", goToLink); // to handle the middle button// TODO: Check why the event is not supported.//@ts-ignore$(document).on("contextmenu", "a", linkContextMenu);-$(document).on("dblclick", "a", (e) => {- e.preventDefault();- e.stopPropagation();-- const $link = $(e.target).closest("a");-- const address = $link.attr("href");-- if (address && address.startsWith("http")) {- window.open(address, "_blank");- }-});+// TODO: Check why the event is not supported.+//@ts-ignore+$(document).on("dblclick", "a", goToLink);$(document).on("mousedown", "a", (e) => {if (e.which === 2) {