Fix #6696 by using shell.openExternal (#7737)

This commit is contained in:
Elian Doran 2025-11-15 21:29:30 +02:00 committed by GitHub
commit 39dacafa82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -307,7 +307,8 @@ export function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDo
// Right click is handled separately. // Right click is handled separately.
const isMiddleClick = evt && "which" in evt && evt.which === 2; const isMiddleClick = evt && "which" in evt && evt.which === 2;
const targetIsBlank = ($link?.attr("target") === "_blank"); 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 activate = (isLeftClick && ctrlKey && shiftKey) || (isMiddleClick && shiftKey);
const openInNewWindow = isLeftClick && evt?.shiftKey && !ctrlKey; const openInNewWindow = isLeftClick && evt?.shiftKey && !ctrlKey;
@ -328,20 +329,22 @@ export function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDo
const withinEditLink = $link?.hasClass("ck-link-actions__preview"); const withinEditLink = $link?.hasClass("ck-link-actions__preview");
const outsideOfCKEditor = !$link || $link.closest("[contenteditable]").length === 0; 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/")) { if (hrefLink.toLowerCase().startsWith("http") || hrefLink.startsWith("api/")) {
window.open(hrefLink, "_blank"); 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 { } else {
// Enable protocols supported by CKEditor 5 to be clickable. // Enable protocols supported by CKEditor 5 to be clickable.
if (ALLOWED_PROTOCOLS.some((protocol) => hrefLink.toLowerCase().startsWith(protocol + ":"))) { if (ALLOWED_PROTOCOLS.some((protocol) => hrefLink.toLowerCase().startsWith(protocol + ":"))) {
if ( utils.isElectron()) {
const electron = utils.dynamicRequire("electron");
electron.shell.openExternal(hrefLink);
} else {
window.open(hrefLink, "_blank"); window.open(hrefLink, "_blank");
} }
} }
} }
} }
}
return true; return true;
} }
@ -473,18 +476,9 @@ $(document).on("auxclick", "a", goToLink); // to handle the middle button
// TODO: Check why the event is not supported. // TODO: Check why the event is not supported.
//@ts-ignore //@ts-ignore
$(document).on("contextmenu", "a", linkContextMenu); $(document).on("contextmenu", "a", linkContextMenu);
$(document).on("dblclick", "a", (e) => { // TODO: Check why the event is not supported.
e.preventDefault(); //@ts-ignore
e.stopPropagation(); $(document).on("dblclick", "a", goToLink);
const $link = $(e.target).closest("a");
const address = $link.attr("href");
if (address && address.startsWith("http")) {
window.open(address, "_blank");
}
});
$(document).on("mousedown", "a", (e) => { $(document).on("mousedown", "a", (e) => {
if (e.which === 2) { if (e.which === 2) {