diff --git a/core/quill.js b/core/quill.js index 2ee1578e1e..44bf15dd97 100644 --- a/core/quill.js +++ b/core/quill.js @@ -383,18 +383,13 @@ class Quill { () => { delta = new Delta(delta); const length = this.getLength(); - const deleted = this.editor.deleteText(0, length); + // Quill will set empty editor to \n + const delete1 = this.editor.deleteText(0, length); + // delta always applied before existing content const applied = this.editor.applyDelta(delta); - const lastOp = applied.ops[applied.ops.length - 1]; - if ( - lastOp != null && - typeof lastOp.insert === 'string' && - lastOp.insert[lastOp.insert.length - 1] === '\n' - ) { - this.editor.deleteText(this.getLength() - 1, 1); - applied.delete(1); - } - return deleted.compose(applied); + // Remove extra \n from empty editor initialization + const delete2 = this.editor.deleteText(this.getLength() - 1, 1); + return delete1.compose(applied).compose(delete2); }, source, ); diff --git a/test/unit/core/quill.js b/test/unit/core/quill.js index c508599824..424a979f82 100644 --- a/test/unit/core/quill.js +++ b/test/unit/core/quill.js @@ -429,6 +429,13 @@ describe('Quill', function() { expect(quill.getContents()).toEqual(contents); expect(delta).toEqual(contents.delete(contents.length())); }); + + it('block embed', function() { + const quill = this.initialize(Quill, '

Hello World!

'); + const contents = new Delta().insert({ video: '#' }); + quill.setContents(contents); + expect(quill.getContents()).toEqual(contents); + }); }); describe('setText()', function() {