Skip to content

Commit

Permalink
handle inserting block embeds into list
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Sep 4, 2016
1 parent a747a04 commit fe7765e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions formats/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ class List extends Container {
return { [this.statics.blotName]: this.statics.formats(this.domNode) };
}

insertBefore(blot, ref) {
if (blot instanceof ListItem) {
super.insertBefore(blot, ref);
} else {
let index = ref == null ? this.length() : ref.offset(this);
let after = this.split(index);
after.parent.insertBefore(blot, after);
}
}

optimize() {
super.optimize();
let next = this.next;
Expand Down
29 changes: 29 additions & 0 deletions test/unit/formats/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,33 @@ describe('List', function() {
editor.formatLine(4, 1, { list: 'bullet' });
expect(this.container).toEqualHTML('<ul><li class="ql-align-center">Test</li></ul>');
});

it('insert block embed', function() {
let editor = this.initialize(Editor, '<ol><li>Test</li></ol>');
editor.insertEmbed(2, 'video', 'https://www.youtube.com/embed/QHH3iSeDBLo?showinfo=0');
expect(this.container).toEqualHTML(`
<ol><li>Te</li></ol>
<iframe class="ql-video" frameborder="0" allowfullscreen="true" src="https://www.youtube.com/embed/QHH3iSeDBLo?showinfo=0"></iframe>
<ol><li>st</li></ol>
`);
});

it('insert block embed at beginning', function() {
let editor = this.initialize(Editor, '<ol><li>Test</li></ol>');
editor.insertEmbed(0, 'video', 'https://www.youtube.com/embed/QHH3iSeDBLo?showinfo=0');
expect(this.container).toEqualHTML(`
<iframe class="ql-video" frameborder="0" allowfullscreen="true" src="https://www.youtube.com/embed/QHH3iSeDBLo?showinfo=0"></iframe>
<ol><li>Test</li></ol>
`);
});

it('insert block embed at end', function() {
let editor = this.initialize(Editor, '<ol><li>Test</li></ol>');
editor.insertEmbed(4, 'video', 'https://www.youtube.com/embed/QHH3iSeDBLo?showinfo=0');
expect(this.container).toEqualHTML(`
<ol><li>Test</li></ol>
<iframe class="ql-video" frameborder="0" allowfullscreen="true" src="https://www.youtube.com/embed/QHH3iSeDBLo?showinfo=0"></iframe>
<ol><li><br></li></ol>
`);
});
});

0 comments on commit fe7765e

Please sign in to comment.