diff --git a/packages/extension-mention/src/mention.ts b/packages/extension-mention/src/mention.ts index e116a789..d4f884ff 100644 --- a/packages/extension-mention/src/mention.ts +++ b/packages/extension-mention/src/mention.ts @@ -72,6 +72,31 @@ export const Mention = Node.create({ return `@${node.attrs.id}` }, + addKeyboardShortcuts() { + return { + Backspace: () => this.editor.commands.command(({ tr, state }) => { + let isMention = false + const { selection } = state + const { empty, anchor } = selection + + if (!empty) { + return false + } + + state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => { + if (node.type.name === 'mention') { + isMention = true + tr.insertText(this.options.suggestion.char || '', pos, pos + node.nodeSize) + + return false + } + }) + + return isMention + }), + } + }, + addProseMirrorPlugins() { return [ Suggestion({