fix(link): do not open links twice when not editable #4877 (#5378)

This commit is contained in:
Nick Perez 2024-07-23 10:57:15 +02:00 committed by GitHub
parent 35682d1322
commit c0e5398685
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
"@tiptap/extension-link": patch
---
Links were opening twive when the editor was not editable and openOnclick was true, now openOnClick setting will check if it is editable before trying to open programmatically resolves #4877

View File

@ -1,9 +1,10 @@
import { getAttributes } from '@tiptap/core'
import { Editor, getAttributes } from '@tiptap/core'
import { MarkType } from '@tiptap/pm/model'
import { Plugin, PluginKey } from '@tiptap/pm/state'
type ClickHandlerOptions = {
type: MarkType
type: MarkType;
editor: Editor;
}
export function clickHandler(options: ClickHandlerOptions): Plugin {
@ -15,6 +16,10 @@ export function clickHandler(options: ClickHandlerOptions): Plugin {
return false
}
if (!options.editor.isEditable) {
return false
}
let a = event.target as HTMLElement
const els = []

View File

@ -277,6 +277,7 @@ export const Link = Mark.create<LinkOptions>({
plugins.push(
clickHandler({
type: this.type,
editor: this.editor,
}),
)
}