Skip to content

Commit

Permalink
Retain edit mode on cloned cards
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Nov 18, 2015
1 parent 0001015 commit ebe19b8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/js/models/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ export default class Card extends Section {
}

clone() {
const payload = shallowCopyObject(this.payload);
return this.builder.createCardSection(this.name, payload);
let payload = shallowCopyObject(this.payload);
let card = this.builder.createCardSection(this.name, payload);
// If this card is currently rendered, clone the mode it is
// currently in as the default mode of the new card.
let mode = this._initialMode;
if (this.renderNode && this.renderNode.cardNode) {
mode = this.renderNode.cardNode.mode;
}
card.setInitialMode(mode);
return card;
}

/**
Expand Down
50 changes: 50 additions & 0 deletions tests/acceptance/editor-cards-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Editor } from 'mobiledoc-kit';
import { DIRECTION } from 'mobiledoc-kit/utils/key';
import Position from 'mobiledoc-kit/utils/cursor/position';
import Helpers from '../test-helpers';
import { CARD_MODES } from 'mobiledoc-kit/models/cards';

const { test, module } = Helpers;

Expand Down Expand Up @@ -442,3 +443,52 @@ test('editor ignores events when focus is inside a card', (assert) => {

assert.equal(inputEvents, 1, 'editor handles input event outside of card');
});

test('a moved card retains its inital editing mode', (assert) => {
const mobiledoc = Helpers.mobiledoc.build(({post, markupSection, cardSection}) => {
let card = cardSection('simple-card');
card.setInitialMode(CARD_MODES.EDIT);
return post([
markupSection(),
card
]);
});

editor = new Editor({mobiledoc, cards: [simpleCard]});
editor.render(editorElement);

assert.hasElement('#edit-button', 'precond - card is in edit mode');

editor.run(postEditor => {
let card = editor.post.sections.tail;
postEditor.moveSectionUp(card);
});

assert.hasElement('#edit-button', 'card is still in edit mode');
});

test('a moved card retains its current editing mode', (assert) => {
const mobiledoc = Helpers.mobiledoc.build(({post, markupSection, cardSection}) => {
return post([
markupSection(),
cardSection('simple-card')
]);
});

editor = new Editor({mobiledoc, cards: [simpleCard]});
editor.render(editorElement);

assert.hasNoElement('#edit-button', 'precond - card is not in edit mode');

let card = editor.post.sections.tail;
editor.editCard(card);

assert.hasElement('#edit-button', 'precond - card is in edit mode');

editor.run(postEditor => {
let card = editor.post.sections.tail;
postEditor.moveSectionUp(card);
});

assert.hasElement('#edit-button', 'card is still in edit mode');
});

0 comments on commit ebe19b8

Please sign in to comment.