From 7da4b50f4f8a5fcbf5ed54ef3d10bdcbd6bee8ff Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 22 Sep 2022 21:14:07 -0400 Subject: [PATCH] Allow click on link decoration to open, closes #4076 --- shared/editor/components/Styles.ts | 1 + shared/editor/marks/Link.tsx | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/shared/editor/components/Styles.ts b/shared/editor/components/Styles.ts index e1ba4bfa5..908894dd6 100644 --- a/shared/editor/components/Styles.ts +++ b/shared/editor/components/Styles.ts @@ -755,6 +755,7 @@ mark { } .external-link { + cursor: pointer; display: inline-block; position: relative; top: 2px; diff --git a/shared/editor/marks/Link.tsx b/shared/editor/marks/Link.tsx index 7f89e1fbd..7c62bd00f 100644 --- a/shared/editor/marks/Link.tsx +++ b/shared/editor/marks/Link.tsx @@ -160,7 +160,23 @@ export default class Link extends Mark { Decoration.widget( // place the decoration at the end of the link nodeWithPos.pos + nodeWithPos.node.nodeSize, - () => icon.cloneNode(true), + () => { + const cloned = icon.cloneNode(true); + cloned.addEventListener("click", (event) => { + try { + if (this.options.onClickLink) { + event.stopPropagation(); + event.preventDefault(); + this.options.onClickLink(linkMark.attrs.href, event); + } + } catch (err) { + this.editor.props.onShowToast( + this.options.dictionary.openLinkError + ); + } + }); + return cloned; + }, { // position on the right side of the position side: 1,