Skip to content

Mention plugin: Insert text at position #871

Answered by dtslvr
dtslvr asked this question in Q&A
Discussion options

You must be logged in to vote

I've ended up creating a copy of useMentionPlugin where I override the onAddMention functionality like this:

const onAddMention = useCallback(
  (editor: SPEditor, data: MentionNodeData) => {
    if (targetRange !== null) {
      // Changed the original onAddMention behavior //////
      Transforms.select(editor, targetRange);
      editor.insertText(
        `${data.value}${insertSpaceAfterMention ? " " : ""}`
      );
      ////////////////////////////////////////////////////
    }
  },
  [targetRange, insertSpaceAfterMention]
);

It would be cool to expose onAddMention, similarly to onClickMention.

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@zbeyens
Comment options

@davevilela
Comment options

@davevilela
Comment options

@dylans
Comment options

@davevilela
Comment options

Answer selected by zbeyens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
5 participants