fix: fixes an error when using the mention extension and pasting text ending with "@", fix #2413

This commit is contained in:
Philipp Kühn
2022-01-21 09:29:36 +01:00
parent 878dd5ced7
commit 55fa220899
2 changed files with 7 additions and 6 deletions

View File

@@ -51,9 +51,9 @@ export const Mention = Node.create<MentionOptions>({
]) ])
.run() .run()
}, },
allow: ({ editor, range }) => { allow: ({ state, range }) => {
const $from = editor.state.doc.resolve(range.from) const $from = state.doc.resolve(range.from)
const type = editor.schema.nodes[this.name] const type = state.schema.nodes[this.name]
const allow = !!$from.parent.type.contentMatch.matchType(type) const allow = !!$from.parent.type.contentMatch.matchType(type)
return allow return allow

View File

@@ -1,5 +1,5 @@
import { Editor, Range } from '@tiptap/core' import { Editor, Range } from '@tiptap/core'
import { Plugin, PluginKey } from 'prosemirror-state' import { EditorState, Plugin, PluginKey } from 'prosemirror-state'
import { Decoration, DecorationSet, EditorView } from 'prosemirror-view' import { Decoration, DecorationSet, EditorView } from 'prosemirror-view'
import { findSuggestionMatch } from './findSuggestionMatch' import { findSuggestionMatch } from './findSuggestionMatch'
@@ -29,6 +29,7 @@ export interface SuggestionOptions {
}, },
allow?: (props: { allow?: (props: {
editor: Editor, editor: Editor,
state: EditorState,
range: Range, range: Range,
}) => boolean, }) => boolean,
} }
@@ -167,7 +168,7 @@ export function Suggestion({
}, },
// Apply changes to the plugin state from a view transaction. // Apply changes to the plugin state from a view transaction.
apply(transaction, prev) { apply(transaction, prev, oldState, state) {
const { composing } = editor.view const { composing } = editor.view
const { selection } = transaction const { selection } = transaction
const { empty, from } = selection const { empty, from } = selection
@@ -198,7 +199,7 @@ export function Suggestion({
const decorationId = `id_${Math.floor(Math.random() * 0xFFFFFFFF)}` const decorationId = `id_${Math.floor(Math.random() * 0xFFFFFFFF)}`
// If we found a match, update the current state to show it // If we found a match, update the current state to show it
if (match && allow({ editor, range: match.range })) { if (match && allow({ editor, state, range: match.range })) {
next.active = true next.active = true
next.decorationId = prev.decorationId ? prev.decorationId : decorationId next.decorationId = prev.decorationId ? prev.decorationId : decorationId
next.range = match.range next.range = match.range