diff --git a/src/js/editor/post.js b/src/js/editor/post.js index f87a9d7f2..4efb96017 100644 --- a/src/js/editor/post.js +++ b/src/js/editor/post.js @@ -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; diff --git a/tests/unit/editor/post-test.js b/tests/unit/editor/post-test.js index 7e5e21955..a9a26af94 100644 --- a/tests/unit/editor/post-test.js +++ b/tests/unit/editor/post-test.js @@ -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'); +});