Skip to content

Commit

Permalink
fix slab#1065
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen authored and Tim McClure committed Dec 12, 2016
1 parent 25971b5 commit 86df11f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
16 changes: 9 additions & 7 deletions core/quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 1 addition & 2 deletions docs/_includes/standalone/snow.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
<script type="text/javascript">
var quill = new Quill('#snow-container', {
placeholder: 'Compose an epic...',
theme: 'snow',
debug: true
theme: 'snow'
});
</script>
<!-- script -->
8 changes: 8 additions & 0 deletions test/unit/core/quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<p><strong>Bold</strong></p><p>Not bold</p>');
let contents = quill.getContents();
let delta = quill.setContents(contents);
expect(quill.getContents()).toEqual(contents);
expect(delta).toEqual(contents.delete(contents.length()));
});
});

describe('setText()', function() {
Expand Down

0 comments on commit 86df11f

Please sign in to comment.