Skip to content

Commit

Permalink
handle empty post
Browse files Browse the repository at this point in the history
fixes #196
  • Loading branch information
bantic committed Oct 27, 2015
1 parent 9ae12f6 commit ee0645d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/js/editor/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,9 @@ class PostEditor {
* @private
*/
insertPost(position, newPost) {
if (newPost.isBlank) {
return position;
}
const post = this.editor.post;
const shouldSplitSection = newPost.sections.length > 1;

Expand Down
22 changes: 22 additions & 0 deletions tests/unit/editor/post-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,3 +941,25 @@ test('#insertPost multiple sections, insert at middle', (assert) => {
assert.equal(nextPosition.offset, post1.sections.objectAt(1).length,
'nextPosition.offset is correct');
});

test('#insertPost insert empty post does nothing', (assert) => {
const build = Helpers.postAbstract.build;
let post1, post2;
build(({post, markupSection, marker}) => {
post1 = post([markupSection('p', [marker('abc')])]);
post2 = post();
});

const mockEditor = renderBuiltAbstract(post1);
const position = new Position(post1.sections.head, 1);

postEditor = new PostEditor(mockEditor);
let nextPosition = postEditor.insertPost(position, post2);
postEditor.complete();

assert.equal(post1.sections.length, 1, 'still 1 section');
assert.equal(post1.sections.head.text, 'abc', 'same section text');
assert.ok(nextPosition.section === post1.sections.head,
'nextPosition.section correct');
assert.equal(nextPosition.offset, 1, 'nextPosition.offset correct');
});

0 comments on commit ee0645d

Please sign in to comment.