Skip to content

Commit

Permalink
Merge pull request #620 from kevinansfield/blank-post-on-paste-guard
Browse files Browse the repository at this point in the history
Fix error when pasting HTML that parses to a blank doc
  • Loading branch information
mixonic committed Jun 20, 2018
2 parents bbd676b + cd7fa1d commit 3b110e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/js/editor/post/post-inserter.js
Expand Up @@ -278,7 +278,9 @@ export default class Inserter {

insert(cursorPosition, newPost) {
let visitor = new Visitor(this, cursorPosition);
visitor.visit(newPost);
if (!newPost.isBlank) {
visitor.visit(newPost);
}
return visitor.cursorPosition;
}
}
22 changes: 22 additions & 0 deletions tests/acceptance/editor-copy-paste-test.js
Expand Up @@ -412,3 +412,25 @@ test('paste with shift key pastes plain text', (assert) => {

assert.postIsSimilar(editor.post, expected);
});

test('paste with html that parses to blank doc doesn\'t error', (assert) => {
let expected;
let mobiledoc = Helpers.mobiledoc.build(({post, markupSection, marker}) => {
expected = post([
markupSection('p', [])
]);

return post([
markupSection('p', [marker('abcd')])
]);
});

editor = new Editor({mobiledoc, cards});
editor.render(editorElement);

Helpers.dom.setCopyData('text/html', `<div></div>`);
editor.selectRange(editor.post.toRange());
Helpers.dom.triggerPasteEvent(editor);

assert.postIsSimilar(editor.post, expected);
});

0 comments on commit 3b110e6

Please sign in to comment.