add appendText option for suggestions

This commit is contained in:
Philipp Kühn
2018-10-02 23:02:07 +02:00
parent 4a31f8f1ca
commit 0a3b235bca
2 changed files with 7 additions and 0 deletions

View File

@@ -55,6 +55,7 @@ export default class MentionNode extends Node {
return [
SuggestionsPlugin({
command: ({ range, attrs, schema }) => replaceText(range, schema.nodes.mention, attrs),
appendText: ' ',
matcher: this.options.matcher,
items: this.options.items,
onEnter: this.options.onEnter,

View File

@@ -1,5 +1,6 @@
import { Plugin, PluginKey } from 'prosemirror-state'
import { Decoration, DecorationSet } from 'prosemirror-view'
import { insertText } from 'tiptap-commands'
// Create a matcher that matches when a specific character is typed. Useful for @mentions and #tags.
function triggerCharacter({
@@ -61,6 +62,7 @@ export default function SuggestionsPlugin({
allowSpaces: false,
startOfLine: false,
},
appendText = null,
suggestionClass = 'suggestion',
command = () => false,
items = [],
@@ -127,6 +129,10 @@ export default function SuggestionsPlugin({
attrs,
schema: view.state.schema,
})(view.state, view.dispatch, view)
if (appendText) {
insertText(appendText)(view.state, view.dispatch, view)
}
},
}