Skip to content

Commit

Permalink
fix joining line with empty line
Browse files Browse the repository at this point in the history
when first line has more than one child, the second child fails to
insert
  • Loading branch information
jhchen committed Aug 31, 2016
1 parent cd9bcb3 commit fdd9202
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion blots/scroll.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Parchment from 'parchment';
import Emitter from '../core/emitter';
import Block, { BlockEmbed } from './block';
import Break from './break';
import Container from './container';
import CodeBlock from '../formats/code';

Expand Down Expand Up @@ -32,7 +33,8 @@ class Scroll extends Parchment.Scroll {
if (last instanceof CodeBlock) {
last.deleteAt(last.length() - 1, 1);
}
first.moveChildren(last, last.children.head);
let ref = last.children.head instanceof Break ? null : last.children.head;
first.moveChildren(last, ref);
first.remove();
}
this.optimize();
Expand Down
6 changes: 6 additions & 0 deletions test/unit/blots/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ describe('Block', function() {
expect(scroll.domNode).toEqualHTML('<h2>HelloWorld!</h2>');
});

it('join line with empty', function() {
let scroll = this.initialize(Scroll, '<p>Hello<strong>World</strong></p><p><br></p>');
scroll.deleteAt(10, 1);
expect(scroll.domNode).toEqualHTML('<p>Hello<strong>World</strong></p>');
});

it('join empty lines', function() {
let scroll = this.initialize(Scroll, '<h1><br></h1><p><br></p>');
scroll.deleteAt(1, 1);
Expand Down

0 comments on commit fdd9202

Please sign in to comment.