add backspace handler to mentions
This commit is contained in:
@@ -72,6 +72,31 @@ export const Mention = Node.create({
|
|||||||
return `@${node.attrs.id}`
|
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() {
|
addProseMirrorPlugins() {
|
||||||
return [
|
return [
|
||||||
Suggestion({
|
Suggestion({
|
||||||
|
|||||||
Reference in New Issue
Block a user