fix(link-tool): open new window with url when formatted link clicked via ctrl key

This commit is contained in:
Eugeny 2026-03-06 01:33:16 +03:00
commit f3875aeb8a
2 changed files with 14 additions and 3 deletions

View file

@ -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
*

View file

@ -773,12 +773,13 @@ export default class UI extends Module<UINodes> {
*/
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);