From: Aleksander Ɓukasz Date: Tue, 16 Jul 2013 15:09:50 +0000 (+0200) Subject: Jumping to paren parent on text unwrap X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/b2b1e86ea7427a65d532bc3c029a1178875eef33?hp=a72a2ac218147b7c6874fbdc361d0a3fb6532a88 Jumping to paren parent on text unwrap --- diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index c4dc610..23061d9 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -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'); }) }); }); diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 669e06a..230e987 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -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) { diff --git a/modules/documentCanvas/canvasManager.js b/modules/documentCanvas/canvasManager.js index a480d2a..a306d14 100644 --- a/modules/documentCanvas/canvasManager.js +++ b/modules/documentCanvas/canvasManager.js @@ -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})) {