Jumping to paren parent on text unwrap
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 16 Jul 2013 15:09:50 +0000 (17:09 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 16 Jul 2013 15:09:50 +0000 (17:09 +0200)
modules/documentCanvas/canvas/canvas.test3.js
modules/documentCanvas/canvas/documentElement.js
modules/documentCanvas/canvasManager.js

index c4dc610..23061d9 100644 (file)
@@ -576,10 +576,11 @@ describe('Canvas', function() {
                     section = c.doc(),
                     text = section.children()[1].children()[0];
 
-                    text.unwrap();
+                    var newTextContainer = text.unwrap();
 
                     expect(section.children().length).to.equal(1, 'section has one child');
                     expect(section.children()[0].getText()).to.equal('Alice has a cat');
+                    expect(newTextContainer.sameNode(c.doc())).to.equal(true, 'unwrap returns new text parent DocumentNodeElement');
                 })
             });
         });
index 669e06a..230e987 100644 (file)
@@ -315,8 +315,10 @@ $.extend(DocumentTextElement.prototype, {
         }
     },
     unwrap: function() {
-        var parent = this.parent();
+        var parent = this.parent(),
+            toret;
         if(parent.children().length === 1) {
+            toret = parent.parent();
             var grandParent = parent.parent();
             if(grandParent) {
                 var grandParentChildren = grandParent.children(),
@@ -336,6 +338,7 @@ $.extend(DocumentTextElement.prototype, {
                 parent.after(this);
             }
             parent.detach();
+            return toret;
         }
     },
     split: function(params) {
index a480d2a..a306d14 100644 (file)
@@ -194,7 +194,9 @@ Manager.prototype.command = function(command, params) {
         if(this.canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
             this.canvas.list.extractItems({element1: parent1, element2: parent2});
         } else if(!cursor.isSelecting()) {
-            cursor.getPosition().element.unwrap();
+            var toUnwrap = cursor.getPosition().element,
+                parent = toUnwrap.unwrap();
+            this.canvas.setCurrentElement(parent);
         }
     } else if(command === 'wrap-node') {
         if(this.canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {