Skip to content

Commit

Permalink
Update to mobiledoc-kit 0.10.1
Browse files Browse the repository at this point in the history
 * Use async to make tests pass when selection polling is happening
 * Fix some tests by setting mobiledoc so that editor focuses and editor.hasCursor()
 * Fix activeSectionTagNames tests
  • Loading branch information
bantic committed Jul 15, 2016
1 parent e38d621 commit 22c7805
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 186 deletions.
16 changes: 14 additions & 2 deletions addon/components/mobiledoc-editor/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ export default Component.extend({
let editor = this.get('editor');
if (!editor.hasRendered) {
let editorElement = this.$('.mobiledoc-editor__editor')[0];
this._isRenderingEditor = true;
editor.render(editorElement);
this._isRenderingEditor = false;
}
},

Expand All @@ -289,8 +291,18 @@ export default Component.extend({
});
const sectionTags = arrayToMap(sectionParentTagNames);

this.set('activeMarkupTagNames', markupTags);
this.set('activeSectionTagNames', sectionTags);
// Avoid updating this component's properties synchronously while
// rendering the editor (after rendering the component) because it
// causes Ember to display deprecation warnings
if (this._isRenderingEditor) {
Ember.run.next(() => {
this.set('activeMarkupTagNames', markupTags);
this.set('activeSectionTagNames', sectionTags);
});
} else {
this.set('activeMarkupTagNames', markupTags);
this.set('activeSectionTagNames', sectionTags);
}
},

willCreateEditor() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"ember-cli-babel": "^5.1.3",
"ember-cli-htmlbars": "^1.0.0",
"ember-wormhole": "^0.3.4",
"mobiledoc-kit": "^0.9.6"
"mobiledoc-kit": "^0.10.1"
},
"ember-addon": {
"configPath": "tests/dummy/config"
Expand Down
20 changes: 0 additions & 20 deletions tests/helpers/move-cursor-to.js

This file was deleted.

30 changes: 30 additions & 0 deletions tests/helpers/selection.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import Ember from 'ember';

function clearSelection() {
window.getSelection().removeAllRanges();
}

let runLater = (cb) => window.requestAnimationFrame(cb);

export function selectRangeWithEditor(editor, range) {
editor.selectRange(range);
return new Ember.RSVP.Promise(resolve => runLater(resolve));
}

export function selectRange(startNode, startOffset, endNode, endOffset) {
clearSelection();

Expand All @@ -11,4 +20,25 @@ export function selectRange(startNode, startOffset, endNode, endOffset) {

const selection = window.getSelection();
selection.addRange(range);

return new Ember.RSVP.Promise(resolve => runLater(resolve));
}

export function moveCursorTo(context, selector) {
let element = context.$(selector);
if (!element.length) {
throw new Error(`could not find element from selector ${selector}`);
} else if (element.length > 1) {
throw new Error(`ambiguous selector ${selector}`);
}

let selection = window.getSelection();
selection.removeAllRanges();

let node = element[0].firstChild;
let range = document.createRange();
range.selectNode(node);
selection.addRange(range);

return new Ember.RSVP.Promise(resolve => runLater(resolve));
}
5 changes: 0 additions & 5 deletions tests/helpers/simulate-mouse-up.js

This file was deleted.

Loading

0 comments on commit 22c7805

Please sign in to comment.