Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug #395: Error when adding a selection outside the editor while not editing #394

Merged
merged 5 commits into from
May 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/js/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const CALLBACK_QUEUES = {
};

/**
* The Editor is a core component of mobiledoc-kit. After instantiating
* The Editor is a core component of mobiledoc-kit. After instantiating
* an editor, use {@link Editor#render} to display the editor on the web page.
*
* An editor uses a {@link Post} internally to represent the displayed document.
Expand Down Expand Up @@ -409,14 +409,16 @@ class Editor {
* @private
*/
_notifyRangeChange() {
this._resetRange();
this._editState.reset();
if (this.isEditable) {
this._resetRange();
this._editState.reset();

if (this._editState.rangeDidChange()) {
this._rangeDidChange();
}
if (this._editState.inputModeDidChange()) {
this._inputModeDidChange();
if (this._editState.rangeDidChange()) {
this._rangeDidChange();
}
if (this._editState.inputModeDidChange()) {
this._inputModeDidChange();
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions tests/acceptance/editor-selections-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ test('selecting across sections is possible', (assert) => {
assert.equal(editor.activeSections.length, 2, 'selects 2 sections');
});

test('when editing is disabled, the selection detection code is disabled', (assert) => {
$('#qunit-fixture').append('<p>outside section</p>');

editor = new Editor({mobiledoc: mobileDocWithSection});
editor.render(editorElement);
editor.disableEditing();

const firstSection = $('p:contains(one trick pony)')[0];
const outsideSection = $('p:contains(outside section)')[0];

Helpers.dom.selectText(editor ,'trick', firstSection,
'outside', outsideSection);

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

assert.equal(editor.activeSections.length, 0, 'no selection inside the editor');
const selectedText = Helpers.dom.getSelectedText();
assert.ok(selectedText.indexOf('trick pony') !== -1 && selectedText.indexOf('outside') !== -1, 'selects the text');
});

test('selecting an entire section and deleting removes it', (assert) => {
editor = new Editor({mobiledoc: mobileDocWith2Sections});
editor.render(editorElement);
Expand Down