add backspace handler to mentions

This commit is contained in:
Philipp Kühn 2021-01-20 20:17:17 +01:00
parent 578a8365c3
commit 1880b43e37

View File

@ -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({