diff --git a/core/quill.js b/core/quill.js index ceaaa8a1a2..47716d116f 100644 --- a/core/quill.js +++ b/core/quill.js @@ -258,14 +258,16 @@ class Quill { setContents(delta, source = Emitter.sources.API) { return modify.call(this, () => { - delta = new Delta(delta).slice(); - let lastOp = delta.ops[delta.ops.length - 1]; - // Quill contents must always end with newline - if (lastOp == null || lastOp.insert[lastOp.insert.length-1] !== '\n') { - delta.insert('\n'); + let length = this.getLength(); + let deleted = this.editor.deleteText(0, length); + let applied = this.editor.applyDelta(delta); + let lastOp = applied.ops[applied.ops.length - 1]; + if (lastOp != null && lastOp.insert[lastOp.insert.length-1] === '\n') { + this.editor.deleteText(this.getLength() - 1, 1); + applied.delete(1); } - delta.delete(this.getLength()); - return this.editor.applyDelta(delta); + let ret = deleted.compose(applied); + return ret; }, source); } diff --git a/docs/_includes/standalone/snow.html b/docs/_includes/standalone/snow.html index ca04b04800..eec8961312 100644 --- a/docs/_includes/standalone/snow.html +++ b/docs/_includes/standalone/snow.html @@ -22,8 +22,7 @@ \ No newline at end of file diff --git a/test/unit/core/quill.js b/test/unit/core/quill.js index b5dd2d021b..234c9d6446 100644 --- a/test/unit/core/quill.js +++ b/test/unit/core/quill.js @@ -257,6 +257,14 @@ describe('Quill', function() { quill.setContents(new Delta().insert('0123')); expect(quill.getContents()).toEqual(new Delta().insert('0123\n')); }); + + it('inline formatting', function() { + let quill = this.initialize(Quill, '

Bold

Not bold

'); + let contents = quill.getContents(); + let delta = quill.setContents(contents); + expect(quill.getContents()).toEqual(contents); + expect(delta).toEqual(contents.delete(contents.length())); + }); }); describe('setText()', function() {