Quill.js: registering PlainClipboard causes initial editor content to lose all formats

986 Views Asked by At

The PlainClipboard shown in the doc is very useful when we want Quill to clear all formats when content is pasted (e.g., copied from webpages). But if we register this module as 'modules/clipboard', any formats in the initial editor container will be wiped out as well:

<div id="editor-container">
    <ol><li>1</li><li>2</li><li>3</li></ol>
</div>

because the initial content is also processed by the convert() function when the editor is initialized. To workaround this, I used a flag to indicate whether it's editor initialization or normal user pasting:

var quill_initializing = true;

class PlainClipboard extends Clipboard {
    convert(html = null) {
        if (quill_initializing) {
            quill_initializing = false;
            return super.convert(html);
        } else {
            if (typeof html === 'string') {
                this.container.innerHTML = html;
            }
            let text = this.container.innerText;
            this.container.innerHTML = '';
            return new Delta().insert(text);
        }
    }
}

This works for Quill 1.3.1 but after I updated to Quill 1.3.2, this approach stops working.

Is there a way to fix this?

0

There are 0 best solutions below