Skip to content

Commit

Permalink
fix setContents on block embed ending
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Jul 16, 2020
1 parent ff47bb0 commit 84d2234
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
17 changes: 6 additions & 11 deletions core/quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
7 changes: 7 additions & 0 deletions test/unit/core/quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<p>Hello World!</p>');
const contents = new Delta().insert({ video: '#' });
quill.setContents(contents);
expect(quill.getContents()).toEqual(contents);
});
});

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

0 comments on commit 84d2234

Please sign in to comment.