diff --git a/packages/text/src/kits/default-kit.ts b/packages/text/src/kits/default-kit.ts index 56aea0a518..30d78e7dad 100644 --- a/packages/text/src/kits/default-kit.ts +++ b/packages/text/src/kits/default-kit.ts @@ -56,7 +56,7 @@ export const DefaultKit = Extension.create({ }), Typography.configure({}), Link.extend({ inclusive: false }).configure({ - openOnClick: true, + openOnClick: false, HTMLAttributes: { class: 'cursor-pointer', rel: 'noopener noreferrer', target: '_blank' } }) ] diff --git a/plugins/text-editor-resources/src/components/extension/link.ts b/plugins/text-editor-resources/src/components/extension/link.ts index e78f4fa3a1..091c06378a 100644 --- a/plugins/text-editor-resources/src/components/extension/link.ts +++ b/plugins/text-editor-resources/src/components/extension/link.ts @@ -15,6 +15,8 @@ import { showPopup } from '@hcengineering/ui' import { Extension } from '@tiptap/core' +import { type MarkType } from '@tiptap/pm/model' +import { Plugin, PluginKey } from '@tiptap/pm/state' import LinkPopup from '../LinkPopup.svelte' export const LinkUtilsExtension = Extension.create({ @@ -42,6 +44,28 @@ export const LinkUtilsExtension = Extension.create({ }, addProseMirrorPlugins () { - return [] + return [LinkClickHandlerPlugin({ type: this.editor.schema.marks.link })] } }) + +interface LinkClickHandlerOptions { + type: MarkType +} + +export function LinkClickHandlerPlugin (options: LinkClickHandlerOptions): Plugin { + return new Plugin({ + key: new PluginKey('handleClickLink'), + props: { + handleClick: (view, pos, event) => { + const $pos = view.state.doc.resolve(pos) + const link = options.type.isInSet($pos.marks()) + if (typeof link?.attrs.href === 'string') { + window.open(link.attrs.href, link.attrs.target) + return true + } + + return false + } + } + }) +} diff --git a/plugins/text-editor-resources/src/kits/default-kit.ts b/plugins/text-editor-resources/src/kits/default-kit.ts index e67de7cf3d..f2cd3d79bd 100644 --- a/plugins/text-editor-resources/src/kits/default-kit.ts +++ b/plugins/text-editor-resources/src/kits/default-kit.ts @@ -62,7 +62,7 @@ export const DefaultKit = Extension.create({ }), Typography.configure({}), Link.extend({ inclusive: false }).configure({ - openOnClick: true, + openOnClick: false, HTMLAttributes: { class: 'cursor-pointer', rel: 'noopener noreferrer', target: '_blank' } }), CodeBlockHighlighExtension.configure(codeBlockHighlightOptions)