Skip to content

Commit

Permalink
fix line merge behavior
Browse files Browse the repository at this point in the history
If we have <h1>0</h1><h2>2</h2> and delete to newline between the two
headers, should the resulting line be h1 or h2? What if they were
bullets vs lists, or other line formats? Testing on word processors seem
to depend on the format itself, rather than always keeping the first
line's format or the 2nd line's. This does not work well for a
customizable and consistent editor because we do not know the formats
ahead of time, so cannot order based on format. We must either always
take the first line's format or the second line's. Prior to this commit
the editor favored the first and the Delta format favored the second. We
standardize to always favor the second.

Fixes slab#889
  • Loading branch information
jhchen committed Aug 29, 2016
1 parent cf83c49 commit be24c62
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions blots/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Scroll extends Parchment.Scroll {
if (last instanceof CodeBlock) {
last.deleteAt(last.length() - 1, 1);
}
last.moveChildren(first);
last.remove();
first.moveChildren(last, last.children.head);
first.remove();
}
this.optimize();
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/blots/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Block', function() {
it('join lines', function() {
let scroll = this.initialize(Scroll, '<h1>Hello</h1><h2>World!</h2>');
scroll.deleteAt(5, 1);
expect(scroll.domNode).toEqualHTML('<h1>HelloWorld!</h1>');
expect(scroll.domNode).toEqualHTML('<h2>HelloWorld!</h2>');
});

it('join empty lines', function() {
Expand Down
6 changes: 6 additions & 0 deletions test/unit/core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ describe('Editor', function() {
);
expect(this.container).toEqualHTML('<p>0123</p><h1>56</h1><h2>89</h2>');
});

it('code', function() {
let editor = this.initialize(Editor, { html: '<p>0</p><pre>1\n23\n</pre><p><br></p>' });
editor.applyDelta(new Delta().delete(4).retain(1).delete(2));
expect(editor.scroll.domNode.innerHTML).toEqual('<p>2</p>');
});
});

describe('getFormat()', function() {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/formats/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ describe('Code', function() {
it('delete merge before', function() {
let editor = this.initialize(Editor, { html: '<h1>0123</h1><pre>4567\n</pre>' });
editor.deleteText(4, 1);
expect(editor.getDelta()).toEqual(new Delta().insert('01234567').insert('\n', { header: 1 }));
expect(editor.scroll.domNode).toEqualHTML('<h1>01234567\n</h1>');
expect(editor.getDelta()).toEqual(new Delta().insert('01234567').insert('\n', { 'code-block': true }));
expect(editor.scroll.domNode).toEqualHTML('<pre>01234567\n</pre>');
});

it('delete merge after', function() {
let editor = this.initialize(Editor, { html: '<pre>0123\n</pre><h1>4567</h1>' });
editor.deleteText(4, 1);
expect(editor.getDelta()).toEqual(new Delta().insert('01234567').insert('\n', { 'code-block': true }));
expect(editor.scroll.domNode).toEqualHTML('<pre>01234567\n</pre>');
expect(editor.getDelta()).toEqual(new Delta().insert('01234567').insert('\n', { header: 1 }));
expect(editor.scroll.domNode).toEqualHTML('<h1>01234567</h1>');
});

it('replace', function() {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/formats/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ describe('List', function() {
<p>5678</p>`
);
editor.deleteText(2, 5);
expect(this.container).toEqualHTML('<ol><li>0178</li></ol>');
expect(this.container).toEqualHTML('<p>0178</p>');
});

it('delete partial', function() {
let editor = this.initialize(Editor, '<p>0123</p><ul><li>5678</li></ul>');
editor.deleteText(2, 5);
expect(this.container).toEqualHTML('<p>0178</p>');
expect(this.container).toEqualHTML('<ul><li>0178</li></ul>');
});

it('nested list replacement', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Clipboard', function() {
this.quill.clipboard.container.innerHTML = '<strong>|</strong>';
this.quill.clipboard.onPaste(this.event);
setTimeout(() => {
expect(this.quill.root).toEqualHTML('<h1>01<strong>|</strong><em>7</em>8</h1>');
expect(this.quill.root).toEqualHTML('<p>01<strong>|</strong><em>7</em>8</p>');
expect(this.quill.getSelection()).toEqual(new Range(3));
done();
}, 2);
Expand Down

0 comments on commit be24c62

Please sign in to comment.