diff --git a/README.md b/README.md index 86aed1439..c6b7a1d1c 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,7 @@ parsed by the next plugin or the default parser. ## Caveats ### Mobiledoc-kit and the Grammarly extension -`mobiledoc-kit` and the [Grammarly extension](https://www.grammarly.com/) do not play well together (see [issue 422](https://github.com/bustlelabs/mobiledoc-kit/issues/422)). Until this is resolved, you can avoid any such problems by disabling Grammarly for the `mobiledoc-kit` instances on your page. To do this, add the `data-gram="false"` attribute to the `mobiledoc-kit` main DOM element. +`mobiledoc-kit` and the [Grammarly extension](https://www.grammarly.com/) do not play well together (see [issue 422](https://github.com/bustlelabs/mobiledoc-kit/issues/422)). Until this is resolved, you can avoid any such problems by disabling Grammarly for the `mobiledoc-kit` instances on your page. To do this, add the `data-gramm="false"` attribute to the `mobiledoc-kit` main DOM element. ## Contributing diff --git a/src/js/editor/event-manager.js b/src/js/editor/event-manager.js index 2173a048c..7fc423c7c 100644 --- a/src/js/editor/event-manager.js +++ b/src/js/editor/event-manager.js @@ -226,6 +226,11 @@ export default class EventManager { if (!range.isCollapsed) { editor.performDelete(); } + + if (editor.post.isBlank) { + editor._insertEmptyMarkupSectionAtCursor(); + } + let position = editor.range.head; let targetFormat = this.modifierKeys.shift ? 'text' : 'html'; let pastedPost = parsePostFromPaste(event, editor, {targetFormat}); diff --git a/tests/acceptance/editor-copy-paste-test.js b/tests/acceptance/editor-copy-paste-test.js index b99f48842..d6aa95675 100644 --- a/tests/acceptance/editor-copy-paste-test.js +++ b/tests/acceptance/editor-copy-paste-test.js @@ -109,6 +109,20 @@ test('paste plain text with list items', (assert) => { assert.hasElement('#editor ul li:contains(def)', 'list item is pasted'); }); +test('paste plain text into an empty Mobiledoc', (assert) => { + const mobiledoc = Helpers.mobiledoc.build( + ({post}) => { + return post(); + }); + editor = new Editor({mobiledoc}); + editor.render(editorElement); + + Helpers.dom.setCopyData(MIME_TEXT_PLAIN, 'abc'); + Helpers.dom.triggerPasteEvent(editor); + + assert.hasElement('#editor p:contains(abc)', 'pastes the text'); +}); + test('can cut and then paste content', (assert) => { const mobiledoc = Helpers.mobiledoc.build( ({post, markupSection, marker}) => {