params = _.extend({caretTo: 'end'}, params);
var findFirstDirectTextChild = function(e, nodeToLand) {
var byBrowser = this.getCursor().getPosition().element;
- if(byBrowser.parent().sameNode(nodeToLand))
+ if(byBrowser && byBrowser.parent().sameNode(nodeToLand))
return byBrowser;
var children = e.children();
for(var i = 0; i < children.length; i++) {
this._moveCaretToTextElement(textElementToLand, params.caretTo); // as method on element?
if(!(textElementToLand.sameNode(currentTextElement)))
this.publisher('currentTextElementSet', element);
+ } else {
+ document.getSelection().removeAllRanges();
}
if(!(currentNodeElement && currentNodeElement.sameNode(nodeElementToLand))) {
_markAsCurrent(nodeElementToLand);
- if(!textElementToLand)
- document.getSelection().removeAllRanges();
+
this.publisher('currentNodeElementSet', nodeElementToLand);
}
},