Splitting text: Returning node elements involved
[fnpeditor.git] / modules / documentCanvas / canvas / canvas.js
index 50ca6c0..144417a 100644 (file)
@@ -181,7 +181,7 @@ $.extend(Canvas.prototype, {
         params = _.extend({caretTo: 'end'}, params);
         var findFirstDirectTextChild = function(e, nodeToLand) {
             var byBrowser = this.getCursor().getPosition().element;
         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++) {
                 return byBrowser;
             var children = e.children();
             for(var i = 0; i < children.length; i++) {
@@ -217,12 +217,13 @@ $.extend(Canvas.prototype, {
                 this._moveCaretToTextElement(textElementToLand, params.caretTo); // as method on element?
             if(!(textElementToLand.sameNode(currentTextElement)))
                 this.publisher('currentTextElementSet', element);
                 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(!(currentNodeElement && currentNodeElement.sameNode(nodeElementToLand))) {
             _markAsCurrent(nodeElementToLand);
-            if(!textElementToLand)
-                document.getSelection().removeAllRanges();
+
             this.publisher('currentNodeElementSet', nodeElementToLand);
         }
     },
             this.publisher('currentNodeElementSet', nodeElementToLand);
         }
     },