wrapping sibling parents of selected text in new node
[fnpeditor.git] / modules / documentCanvas / canvas / documentElement.js
index 9768236..cfdac5d 100644 (file)
@@ -83,6 +83,7 @@ $.extend(DocumentElement.prototype, {
     detach: function() {
         this.dom().detach();
         this.canvas = null;
+        return this;
     },
 
     markAsCurrent: function() {
@@ -478,6 +479,10 @@ $.extend(DocumentTextElement.prototype, {
                     idx = grandParent.childIndex(parent),
                     prev = idx - 1 > -1 ? grandParentChildren[idx-1] : null,
                     next = idx + 1 < grandParentChildren.length ? grandParentChildren[idx+1] : null;
+                
+                prev = (prev instanceof DocumentTextElement) ? prev : null;
+                next = (next instanceof DocumentTextElement) ? next : null;
+
                 if(prev && next) {
                     prev.setText(prev.getText() + this.getText() + next.getText());
                     next.detach();