Skip to content

Commit

Permalink
Optionally delete full mention chip
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy-Sun committed Oct 21, 2022
1 parent 2b69f34 commit fa18c09
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/extension-mention/src/mention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type MentionOptions = {
options: MentionOptions,
node: ProseMirrorNode,
}) => string,
deleteOnBackspace: boolean,
suggestion: Omit<SuggestionOptions, 'editor'>,
}

Expand All @@ -23,6 +24,7 @@ export const Mention = Node.create<MentionOptions>({
renderLabel({ options, node }) {
return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`
},
deleteOnBackspace: false,
suggestion: {
char: '@',
pluginKey: MentionPluginKey,
Expand Down Expand Up @@ -144,7 +146,11 @@ export const Mention = Node.create<MentionOptions>({
state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
if (node.type.name === this.name) {
isMention = true
tr.insertText(this.options.suggestion.char || '', pos, pos + node.nodeSize)
tr.insertText(
this.options.deleteOnBackspace ? '' : this.options.suggestion.char || '',
pos,
pos + node.nodeSize,
)

return false
}
Expand Down

0 comments on commit fa18c09

Please sign in to comment.