mirror of
https://github.com/codex-team/editor.js
synced 2026-03-15 07:05:48 +01:00
fix(link-tool): open new window with url when formatted link clicked via ctrl key
This commit is contained in:
parent
b69aa1ed25
commit
f3875aeb8a
2 changed files with 14 additions and 3 deletions
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue