From f3875aeb8a4e97bf3110a107c80df0079453404e Mon Sep 17 00:00:00 2001 From: Eugeny Date: Fri, 6 Mar 2026 01:33:16 +0300 Subject: [PATCH] fix(link-tool): open new window with url when formatted link clicked via ctrl key --- src/components/dom.ts | 10 ++++++++++ src/components/modules/ui.ts | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/dom.ts b/src/components/dom.ts index 0cbfbeda..573c2d98 100644 --- a/src/components/dom.ts +++ b/src/components/dom.ts @@ -566,6 +566,16 @@ export default class Dom { return element.tagName.toLowerCase() === 'a'; } + /** + * Returns the closest ancestor anchor (A tag) of the given element (including itself) + * + * @param element - element to check + * @returns {HTMLAnchorElement | null} + */ + public static getAnchor(element: Element): HTMLAnchorElement | null { + return element.closest("a"); + } + /** * Return element's offset related to the document * diff --git a/src/components/modules/ui.ts b/src/components/modules/ui.ts index a4d3baad..708592df 100644 --- a/src/components/modules/ui.ts +++ b/src/components/modules/ui.ts @@ -773,12 +773,13 @@ export default class UI extends Module { */ const element = event.target as Element; const ctrlKey = event.metaKey || event.ctrlKey; - - if ($.isAnchor(element) && ctrlKey) { + const anchor = $.getAnchor(element); + + if (anchor && ctrlKey) { event.stopImmediatePropagation(); event.stopPropagation(); - const href = element.getAttribute('href'); + const href = anchor.getAttribute('href'); const validUrl = _.getValidUrl(href); _.openTab(validUrl);