editor: fix internal links opening in new tab in readonly notes

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2025-07-16 11:30:17 +05:00
parent 20138505c4
commit 94acc241d9

View File

@@ -30,46 +30,48 @@ export function clickHandler(options: ClickHandlerOptions): Plugin {
return new Plugin({
key: new PluginKey("handleClickLink"),
props: {
handleClick: (view, pos, event) => {
const isMainClick = event.button === 0;
const isAuxClick = event.button === 1;
if (!isMainClick && !isAuxClick) {
return false;
}
let a = event.target as HTMLElement;
const els = [];
while (a.nodeName !== "DIV") {
els.push(a);
a = a.parentNode as HTMLElement;
}
if (!els.find((value) => value.nodeName === "A")) {
return false;
}
const attrs = getAttributes(view.state, options.type.name);
const link = event.target as HTMLLinkElement;
const href = link?.href ?? attrs.href;
// const target = link?.target ?? attrs.target;
if (link && href) {
if (options.editor.storage.openLink) {
event.preventDefault();
setTimeout(() =>
options.editor.storage.openLink?.(
href,
isAuxClick || event.ctrlKey || event.metaKey
)
);
handleDOMEvents: {
click: (view, event) => {
const isMainClick = event.button === 0;
const isAuxClick = event.button === 1;
if (!isMainClick && !isAuxClick) {
return false;
}
return true;
}
let a = event.target as HTMLElement;
const els = [];
return false;
while (a.nodeName !== "DIV") {
els.push(a);
a = a.parentNode as HTMLElement;
}
if (!els.find((value) => value.nodeName === "A")) {
return false;
}
const attrs = getAttributes(view.state, options.type.name);
const link = event.target as HTMLLinkElement;
const href = link?.href ?? attrs.href;
// const target = link?.target ?? attrs.target;
if (link && href) {
if (options.editor.storage.openLink) {
event.preventDefault();
setTimeout(() =>
options.editor.storage.openLink?.(
href,
isAuxClick || event.ctrlKey || event.metaKey
)
);
}
return true;
}
return false;
}
}
}
});