I am using onPaste function in quill editor. But whenever I tried to paste some text, the text get started as below format. How can I display them as the same content copied from?
Below is the code that I had used in order to get either html/text or plain/text
import Quill from 'quill'
const Clipboard = Quill.import('modules/clipboard')
const Delta = Quill.import('delta')
class PlainClipboard extends Clipboard {
onPaste(e) {
e.preventDefault()
this.quill.focus();
const range = this.quill.getSelection()
const text = e.clipboardData.types.find(type => type == "text/html") == "text/html" ? e.clipboardData.getData('text/html')
: e.clipboardData.types.find(type=>type == "text/rtf") == "text/rtf" ? e.clipboardData.getData('text/html')
: e.clipboardData.getData('text/plain');
const delta = new Delta()
.retain(range.index)
.delete(range.length)
.insert(text)
const index = text.length + range.index
const length = 0
this.quill.updateContents(delta, 'silent')
this.quill.setSelection(index, length, 'silent')
this.quill.scrollIntoView()
}
Read highlighted "Test" content is copied and pasted but instead of displaying as it was before, the chuck of html code is displayed.