mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user