Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/text/src/kits/default-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const DefaultKit = Extension.create<DefaultKitOptions>({
}),
Typography.configure({}),
Link.extend({ inclusive: false }).configure({
openOnClick: true,
openOnClick: false,
HTMLAttributes: { class: 'cursor-pointer', rel: 'noopener noreferrer', target: '_blank' }
})
]
Expand Down
26 changes: 25 additions & 1 deletion plugins/text-editor-resources/src/components/extension/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>({
Expand Down Expand Up @@ -42,6 +44,28 @@ export const LinkUtilsExtension = Extension.create<any>({
},

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
}
}
})
}
2 changes: 1 addition & 1 deletion plugins/text-editor-resources/src/kits/default-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const DefaultKit = Extension.create<DefaultKitOptions>({
}),
Typography.configure({}),
Link.extend({ inclusive: false }).configure({
openOnClick: true,
openOnClick: false,
HTMLAttributes: { class: 'cursor-pointer', rel: 'noopener noreferrer', target: '_blank' }
}),
CodeBlockHighlighExtension.configure(codeBlockHighlightOptions)
Expand Down
Loading