Merge pull request #8364 from 01zulfi/editor/fix-readonly-links

editor: fix internal links opening in new tab in readonly notes
This commit is contained in:
Abdullah Atta
2025-07-16 11:50:58 +05:00
committed by GitHub

View File

@@ -30,46 +30,48 @@ export function clickHandler(options: ClickHandlerOptions): Plugin {
return new Plugin({ return new Plugin({
key: new PluginKey("handleClickLink"), key: new PluginKey("handleClickLink"),
props: { props: {
handleClick: (view, pos, event) => { handleDOMEvents: {
const isMainClick = event.button === 0; click: (view, event) => {
const isAuxClick = event.button === 1; const isMainClick = event.button === 0;
if (!isMainClick && !isAuxClick) { const isAuxClick = event.button === 1;
return false; 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
)
);
} }
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;
}
} }
} }
}); });