From 3f7e6b219b572d2aa06618ce125ba86cd2fcd0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 20 Aug 2021 09:33:16 +0200 Subject: [PATCH] fix: prevent multiple space characters after mention node, fix #1703 --- packages/extension-mention/src/mention.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) 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()