A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
editor: fix internal links opening in new tab in readonly notes Signed-off-by: 01zulfi <[email protected]>
01zulfi94acc241d9e1
diff --git a/packages/editor/src/extensions/link/helpers/clickHandler.ts b/packages/editor/src/extensions/link/helpers/clickHandler.tsindex 8e75748db..4f47bf60c 100644--- a/packages/editor/src/extensions/link/helpers/clickHandler.ts+++ b/packages/editor/src/extensions/link/helpers/clickHandler.ts@@ -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;- }+ handleDOMEvents: {+ click: (view, event) => {+ const isMainClick = event.button === 0;+ const isAuxClick = event.button === 1;+ if (!isMainClick && !isAuxClick) {+ return false;+ }- let a = event.target as HTMLElement;- const els = [];+ let a = event.target as HTMLElement;+ const els = [];- while (a.nodeName !== "DIV") {- els.push(a);- a = a.parentNode as HTMLElement;- }+ while (a.nodeName !== "DIV") {+ els.push(a);+ a = a.parentNode as HTMLElement;+ }- if (!els.find((value) => value.nodeName === "A")) {- return false;- }+ if (!els.find((value) => value.nodeName === "A")) {+ return false;+ }++ const attrs = getAttributes(view.state, options.type.name);+ const link = event.target as HTMLLinkElement;- 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;- 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+ )+ );+ }- if (link && href) {- if (options.editor.storage.openLink) {- event.preventDefault();- setTimeout(() =>- options.editor.storage.openLink?.(- href,- isAuxClick || event.ctrlKey || event.metaKey- )- );+ return true;}- return true;+ return false;}-- return false;}}});