From 8c9d3b6afa002ad4db684dadcf8a50ca27f8701d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 8 Aug 2013 13:01:22 +0200 Subject: [PATCH 1/1] Fixing text unwrapping --- modules/documentCanvas/canvas/canvas.test3.js | 13 +++++++++++++ modules/documentCanvas/canvas/documentElement.js | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index 0fe89cc..6a87d95 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -732,6 +732,19 @@ describe('Canvas', function() { 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'); }); + + it('unwraps text element from its parent - first child case', function() { + var c = canvas.fromXML('
Sometext
'), + section = c.doc(), + span = section.children()[0]; + + span.children()[0].unwrap(); + + var sectionChildren = section.children(); + + expect(sectionChildren).to.have.length(1); + expect(sectionChildren[0].getText()).to.equal('Sometext'); + }); }); }); diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 4c09b75..7dd1f7d 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -528,8 +528,9 @@ $.extend(DocumentTextElement.prototype, { prev.setText(prev.getText() + this.getText() + next.getText()); next.detach(); } else if (prev || next) { - var target = prev ? prev : next; - target.setText(target.getText() + this.getText()); + var target = prev ? prev : next, + newText = prev ? target.getText() + this.getText() : this.getText() + target.getText(); + target.setText(newText); } else { parent.after(this); } -- 2.20.1