Skip to content

Commit cfbee3a

Browse files
committed
Fixed non-editable link clicks opening duplicate tabs
1 parent 54f4f7a commit cfbee3a

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

packages/core/src/editor/managers/ExtensionManager/extensions.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
AnyExtension as AnyTiptapExtension,
33
extensions,
44
getAttributes,
5+
mergeAttributes,
56
Node,
67
Extension as TiptapExtension,
78
} from "@tiptap/core";
@@ -117,7 +118,13 @@ export function getDefaultTiptapExtensions(
117118

118119
let link: HTMLAnchorElement | null = null;
119120

120-
if (event.target instanceof HTMLAnchorElement) {
121+
if (
122+
event.target instanceof HTMLAnchorElement &&
123+
// Differentiate between link inline content and read-only links.
124+
event.target.hasAttribute("data-inline-content-type") &&
125+
event.target.getAttribute("data-inline-content-type") ===
126+
"link"
127+
) {
121128
link = event.target;
122129
} else {
123130
const target = event.target as HTMLElement | null;
@@ -127,9 +134,11 @@ export function getDefaultTiptapExtensions(
127134

128135
const root = tiptapEditor.view.dom;
129136

130-
// Tntentionally limit the lookup to the editor root.
137+
// Intentionally limit the lookup to the editor root.
131138
// Using tag names like DIV as boundaries breaks with custom NodeViews,
132-
link = target.closest<HTMLAnchorElement>("a");
139+
link = target.closest<HTMLAnchorElement>(
140+
'a[data-inline-content-type="link"]',
141+
);
133142

134143
if (link && !root.contains(link)) {
135144
link = null;
@@ -177,7 +186,13 @@ export function getDefaultTiptapExtensions(
177186
defaultProtocol: DEFAULT_LINK_PROTOCOL,
178187
// only call this once if we have multiple editors installed. Or fix https://github.com/ueberdosis/tiptap/issues/5450
179188
protocols: LINKIFY_INITIALIZED ? [] : VALID_LINK_PROTOCOLS,
180-
HTMLAttributes: options.links?.HTMLAttributes ?? {},
189+
HTMLAttributes: mergeAttributes(
190+
{
191+
className: "bn-inline-content-section",
192+
"data-inline-content-type": "link",
193+
},
194+
options.links?.HTMLAttributes ?? {},
195+
),
181196
// Always false as we handle clicks ourselves above.
182197
openOnClick: false,
183198
}),

0 commit comments

Comments
 (0)