Skip to content

Mentions dont show up when I try to use quill.getText() #297

Answered by angelaki
alexbennycodes asked this question in Q&A
Discussion options

You must be logged in to vote

I just checked the editors getText() method and it seams like that's something, mention can't control:

  getText(index: number, length: number): string {
    return this.getContents(index, length)
      .filter(op => typeof op.insert === 'string')
      .map(op => op.insert)
      .join('');
  }

But since it's quite easy, I've created my own getText-method, respecting mentions:

quill.getContent().ops
    .filter(op => typeof op.insert === 'string' || op.insert?.mention instanceof DOMStringMap)
    .map(op => typeof op.insert === 'string' ? op.insert : `$$${op.insert.mention.id}`)
    .join('');

Even sexier, you can just override the prototype:

Quill.prototype.getText = function (this: a…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by csculley
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #272 on July 16, 2023 08:30.