From f0599fd59924ae14e4f4e291553be88bae3f1fa0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 11 Jul 2013 10:51:44 +0200 Subject: [PATCH] Unwrapping DocumentTextElement --- modules/documentCanvas/canvas/canvas.test3.js | 13 +++++++++++++ modules/documentCanvas/canvas/documentElement.js | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index ff7c5c4..ba14af7 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -426,6 +426,19 @@ describe('Canvas', function() { expect(wrapperChildren[2].getText()).to.equal(' cat'); }); }); + + describe('unwrapping', function() { + it('unwraps DocumentTextElement from its parent DocumentNodeElement if it\'s its only child', function() { + var c = canvas.fromXML('
Alice has a cat
'), + section = c.doc(), + text = section.children()[0].children()[0]; + + text.unwrap(); + + expect(section.children().length).to.equal(1); + expect(section.children()[0].getText()).to.equal('Alice has a cat'); + }) + }); }); describe('Lists api', function() { diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index f2ef09c..89e98a2 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -198,6 +198,13 @@ $.extend(DocumentTextElement.prototype, { return DocumentElement.prototype.wrapWithNodeElement.call(this, wlxmlNode); } }, + unwrap: function() { + if(this.parent().children().length === 1) { + var parent = this.parent(); + parent.after(this); + parent.detach(); + } + }, split: function(params) { var parentElement = this.parent(), myIdx = parentElement.childIndex(this), -- 2.20.1