fix: prevent multiple space characters after mention node, fix #1703

This commit is contained in:
Philipp Kühn
2021-08-20 09:33:16 +02:00
parent bafe94f512
commit 3f7e6b219b

View File

@@ -26,6 +26,17 @@ export const Mention = Node.create<MentionOptions>({
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()