mirror of
https://github.com/colanode/colanode.git
synced 2026-02-24 11:59:53 +01:00
Fix internal link handling in editor (#315)
This commit is contained in:
@@ -23,22 +23,27 @@ export const LinkMark = Link.extend({
|
||||
props: {
|
||||
handleClick: (_, __, event) => {
|
||||
// Don't handle clicks on links that are created and handled by Tanstack Router
|
||||
// Find the link element that is closest to the target - based on the original Tiptap link implementation
|
||||
|
||||
let link: HTMLAnchorElement | null = null;
|
||||
|
||||
if (event.target instanceof HTMLAnchorElement) {
|
||||
link = event.target;
|
||||
} else {
|
||||
let a = event.target as HTMLElement;
|
||||
const els = [];
|
||||
|
||||
while (a.nodeName !== 'DIV') {
|
||||
els.push(a);
|
||||
a = a.parentNode as HTMLElement;
|
||||
const target = event.target as HTMLElement | null;
|
||||
if (!target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const root = this.editor.view.dom;
|
||||
|
||||
// Tntentionally limit the lookup to the editor root.
|
||||
// Using tag names like DIV as boundaries breaks with custom NodeViews,
|
||||
link = target.closest<HTMLAnchorElement>('a');
|
||||
|
||||
if (link && !root.contains(link)) {
|
||||
link = null;
|
||||
}
|
||||
link = els.find(
|
||||
(value) => value.nodeName === 'A'
|
||||
) as HTMLAnchorElement;
|
||||
}
|
||||
|
||||
if (!link) {
|
||||
|
||||
Reference in New Issue
Block a user