diff --git a/packages/extension-mention/src/mention.ts b/packages/extension-mention/src/mention.ts index 0189b5f9..75dd7d9f 100644 --- a/packages/extension-mention/src/mention.ts +++ b/packages/extension-mention/src/mention.ts @@ -26,6 +26,17 @@ export const Mention = Node.create({ char: '@', pluginKey: MentionPluginKey, command: ({ editor, range, props }) => { + // increase range.to by one when the next node is of type "text" + // and starts with a space character + const nodeAfter = editor.view.state.selection.$to.nodeAfter + const overrideSpace = nodeAfter?.text + ? /^\s/.test(nodeAfter.text) + : false + + if (overrideSpace) { + range.to += 1 + } + editor .chain() .focus()