Skip to content

Commit

Permalink
bugfix: Allow selecting across sections
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Aug 5, 2015
1 parent d0c834c commit f89d346
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/js/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ export default class Post {
this.sections = [];
}
appendSection(section) {
section.post = this;
this.sections.push(section);
}
prependSection(section) {
section.post = this;
this.sections.unshift(section);
}
replaceSection(section, newSection) {
section.post = this;
this.insertSectionAfter(newSection, section);
this.removeSection(section);
}
Expand All @@ -37,6 +40,7 @@ export default class Post {
}

insertSectionAfter(section, previousSection) {
section.post = this;
let foundIndex = -1;

for (let i=0; i<this.sections.length; i++) {
Expand Down
3 changes: 2 additions & 1 deletion tests/acceptance/editor-commands-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const mobiledoc = {
sections: [
[],
[[
1, 'P', [[[], 0, 'THIS IS A TEST']]
1, 'P', [[[], 0, 'THIS IS A TEST']],
1, 'P', [[[], 0, 'second section']]
]]
]
};
Expand Down
56 changes: 56 additions & 0 deletions tests/acceptance/editor-selections-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Editor } from 'content-kit-editor';
import Helpers from '../test-helpers';
import { MOBILEDOC_VERSION } from 'content-kit-editor/renderers/mobiledoc';

const { test, module } = QUnit;

let fixture, editor, editorElement;

const mobileDocWith2Sections = {
version: MOBILEDOC_VERSION,
sections: [
[],
[
[1, "P", [
[[], 0, "first section"]
]],
[1, "P", [
[[], 0, "second section"]
]]
]
]
};

module('Acceptance: Editor Selections', {
beforeEach() {
fixture = document.getElementById('qunit-fixture');
editorElement = document.createElement('div');
editorElement.setAttribute('id', 'editor');
fixture.appendChild(editorElement);
},

afterEach() {
if (editor) {
editor.destroy();
}
}
});

test('selecting across sections is possible', (assert) => {
const done = assert.async();

editor = new Editor(editorElement, {mobiledoc: mobileDocWith2Sections});

let firstSection = $('p:contains(first section)')[0];
let secondSection = $('p:contains(second section)')[0];

Helpers.dom.selectText('section', firstSection,
'second', secondSection);

Helpers.dom.triggerEvent(document, 'mouseup');

setTimeout(() => {
assert.equal(editor.activeSections.length, 2, 'selects 2 sections');
done();
});
});

0 comments on commit f89d346

Please sign in to comment.