mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-28 07:40:13 +08:00
add backspace handler to mentions
This commit is contained in:
parent
578a8365c3
commit
1880b43e37
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user