Skip to content

Commit

Permalink
Fixed copy/paste of card section following a list section
Browse files Browse the repository at this point in the history
closes #637
- if a non-markerable section immediately followed a list section the `post.trimTo()` was not appending it to the post
- resetting the `sectionParent` to the `post` object when hitting a non-markerable section allows all sections to be appended to the constrained post
  • Loading branch information
kevinansfield committed Aug 1, 2018
1 parent ff97899 commit 5a171e1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/js/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class Post {
);
} else {
newSection = section.clone();
sectionParent = post;
}
if (sectionParent) {
sectionParent.sections.append(newSection);
Expand Down
40 changes: 40 additions & 0 deletions tests/acceptance/editor-copy-paste-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,46 @@ test('copy-paste can copy list sections', (assert) => {
assert.hasElement($('#editor ul:eq(0) li:contains(list)'));
});

test('copy-paste can copy card following list section', (assert) => {
const mobiledoc = Helpers.mobiledoc.build(
({post, markupSection, marker, listSection, listItem, cardSection}) => {
return post([
markupSection('p', [marker('abc')]),
listSection('ul', [
listItem([marker('list')])
]),
cardSection('test-card', {foo: 'bar'}),
markupSection('p', [marker('123')])
]);
});
let cards = [{
name: 'test-card',
type: 'dom',
render({ payload }) {
return $(`<div class='${payload.foo}'>${payload.foo}</div>`)[0];
}
}];
editor = new Editor({mobiledoc, cards});
editor.render(editorElement);

assert.hasElement('#editor .bar', 'precond - renders card');

Helpers.dom.selectText(editor, 'c', editor.element, '3', editor.element);

Helpers.dom.triggerCopyEvent(editor);

let textNode = $('#editor p')[1].childNodes[0];
assert.equal(textNode.textContent, '123', 'precond - correct textNode');

Helpers.dom.moveCursorTo(editor, textNode, 3); // end of node
Helpers.dom.triggerPasteEvent(editor);

assert.equal($('#editor ul').length, 2, 'pastes the list');
assert.hasElement('#editor ul:eq(1) li:contains(list)');

assert.equal($('#editor .bar').length, 2, 'renders a second card');
});

test('copy sets html & text for pasting externally', (assert) => {
const mobiledoc = Helpers.mobiledoc.build(
({post, markupSection, marker}) => {
Expand Down

0 comments on commit 5a171e1

Please sign in to comment.