Skip to content

Commit 39dacaf

Browse files
authored
Fix #6696 by using shell.openExternal (#7737)
2 parents 2840df8 + 57deb36 commit 39dacaf

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

apps/client/src/services/link.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ export function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDo
307307
// Right click is handled separately.
308308
const isMiddleClick = evt && "which" in evt && evt.which === 2;
309309
const targetIsBlank = ($link?.attr("target") === "_blank");
310-
const openInNewTab = (isLeftClick && ctrlKey) || isMiddleClick || targetIsBlank;
310+
const isDoubleClick = isLeftClick && evt?.type === "dblclick";
311+
const openInNewTab = (isLeftClick && ctrlKey) || isDoubleClick || isMiddleClick || targetIsBlank;
311312
const activate = (isLeftClick && ctrlKey && shiftKey) || (isMiddleClick && shiftKey);
312313
const openInNewWindow = isLeftClick && evt?.shiftKey && !ctrlKey;
313314

@@ -328,16 +329,18 @@ export function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDo
328329
const withinEditLink = $link?.hasClass("ck-link-actions__preview");
329330
const outsideOfCKEditor = !$link || $link.closest("[contenteditable]").length === 0;
330331

331-
if (openInNewTab || (withinEditLink && (isLeftClick || isMiddleClick)) || (outsideOfCKEditor && (isLeftClick || isMiddleClick))) {
332+
if (openInNewTab || openInNewWindow || (isLeftClick && (withinEditLink || outsideOfCKEditor))) {
332333
if (hrefLink.toLowerCase().startsWith("http") || hrefLink.startsWith("api/")) {
333334
window.open(hrefLink, "_blank");
334-
} else if ((hrefLink.toLowerCase().startsWith("file:") || hrefLink.toLowerCase().startsWith("geo:")) && utils.isElectron()) {
335-
const electron = utils.dynamicRequire("electron");
336-
electron.shell.openPath(hrefLink);
337335
} else {
338336
// Enable protocols supported by CKEditor 5 to be clickable.
339337
if (ALLOWED_PROTOCOLS.some((protocol) => hrefLink.toLowerCase().startsWith(protocol + ":"))) {
340-
window.open(hrefLink, "_blank");
338+
if ( utils.isElectron()) {
339+
const electron = utils.dynamicRequire("electron");
340+
electron.shell.openExternal(hrefLink);
341+
} else {
342+
window.open(hrefLink, "_blank");
343+
}
341344
}
342345
}
343346
}
@@ -473,18 +476,9 @@ $(document).on("auxclick", "a", goToLink); // to handle the middle button
473476
// TODO: Check why the event is not supported.
474477
//@ts-ignore
475478
$(document).on("contextmenu", "a", linkContextMenu);
476-
$(document).on("dblclick", "a", (e) => {
477-
e.preventDefault();
478-
e.stopPropagation();
479-
480-
const $link = $(e.target).closest("a");
481-
482-
const address = $link.attr("href");
483-
484-
if (address && address.startsWith("http")) {
485-
window.open(address, "_blank");
486-
}
487-
});
479+
// TODO: Check why the event is not supported.
480+
//@ts-ignore
481+
$(document).on("dblclick", "a", goToLink);
488482

489483
$(document).on("mousedown", "a", (e) => {
490484
if (e.which === 2) {

0 commit comments

Comments
 (0)