QuillJS - remove formatting when pasting into the editor

4.8k views Asked by At

I previously used https://github.com/quilljs/quill/issues/1184#issuecomment-403657128 to make sure that no one can paste formatted text in the QuillJS editor, because I would like people to only use the few editing buttons that I enabled from QuillJs. Since then, it stopped working for me. My question is:

  • is this working for everyone else?
  • if no, do you know of an alternative?
1

There are 1 answers

0
AudioBubble On BEST ANSWER

One thing about https://github.com/quilljs/quill/issues/1184#issuecomment-403657128 that may behave different than you may have expected could be the 'silent'.

"APIs causing text to change may also be called with a "silent" source, in which case text-change will not be emitted. This is not recommended as it will likely break the undo stack and other functions that rely on a full record of text changes." [ https://quilljs.com/docs/api/#events ]

So if you expected to get the text-change event get emitted but do not get it, then change these two lines

this.quill.updateContents(delta, 'silent')
this.quill.setSelection(index, length, 'silent')

like this:

this.quill.updateContents(delta, 'user')
this.quill.setSelection(index, length, 'user')

Then the text-change event will get fired.