Skip to content

Commit

Permalink
fix copy/paste of partial lists
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Apr 17, 2019
1 parent 0178431 commit ab9ef48
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
14 changes: 9 additions & 5 deletions core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,15 @@ function convertListHTML(items, lastIndent, types) {
const [tag, attribute] = getListType(type);
if (indent > lastIndent) {
types.push(type);
return `<${tag}><li${attribute}>${convertHTML(
child,
offset,
length,
)}${convertListHTML(rest, indent, types)}`;
if (indent === lastIndent + 1) {
types.push(type);
return `<${tag}><li${attribute}>${convertHTML(
child,
offset,
length,
)}${convertListHTML(rest, indent, types)}`;
}
return `<${tag}><li>${convertListHTML(items, lastIndent + 1, types)}`;
}
const previousType = types[types.length - 1];
if (indent === lastIndent && type === previousType) {
Expand Down
30 changes: 30 additions & 0 deletions test/unit/core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,36 @@ describe('Editor', function() {
`);
});

it('partial list', function() {
const editor = this.initialize(
Editor,
`
<ol>
<li data-list="ordered">1111</li>
<li data-list="ordered" class="ql-indent-1">AAAA</li>
<li data-list="ordered" class="ql-indent-2">IIII</li>
<li data-list="ordered" class="ql-indent-1">BBBB</li>
<li data-list="ordered">2222</li>
</ol>
`,
);
expect(editor.getHTML(12, 12)).toEqualHTML(`
<ol>
<li>
<ol>
<li>
<ol>
<li>II</li>
</ol>
</li>
<li>BBBB</li>
</ol>
</li>
<li>2222</li>
</ol>
`);
});

it('text within tag', function() {
const editor = this.initialize(Editor, '<p><a>a</a></p>');
expect(editor.getHTML(0, 1)).toEqual('<a>a</a>');
Expand Down
13 changes: 13 additions & 0 deletions test/unit/modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,19 @@ describe('Clipboard', function() {
);
});

it('html partial list', function() {
const delta = this.clipboard.convert({
html:
'<ol><li><ol><li><ol><li>iiii</li></ol></li><li>bbbb</li></ol></li><li>2222</li></ol>',
});
expect(delta).toEqual(
new Delta()
.insert('iiii\n', { list: 'ordered', indent: 2 })
.insert('bbbb\n', { list: 'ordered', indent: 1 })
.insert('2222\n', { list: 'ordered' }),
);
});

it('html table', function() {
const delta = this.clipboard.convert({
html:
Expand Down

0 comments on commit ab9ef48

Please sign in to comment.