From: Aleksander Ɓukasz Date: Thu, 25 Jul 2013 07:40:19 +0000 (+0200) Subject: Fixing xml output after removing text with white space X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/ad64ee06bd810b02f60b474b12d397eb4e95bdff?ds=inline Fixing xml output after removing text with white space --- diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index 50f03e9..eeab1b2 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -1212,6 +1212,29 @@ describe('Canvas', function() { expect(xmlOut).to.equal(xmlIn); }); + it('keeps white space after detaching text element', function() { + var xmlIn = '
header
\ + \ + text1\ + \ +
', + expectedXmlOut = '
header
\ + \ + \ + \ +
', + c = canvas.fromXML(xmlIn), + children = c.doc().children(), + text = children[children.length-1]; + + expect(text.getText()).to.equal('text1'); + + text.detach(); + + var xmlOut = c.toXML(); + expect(xmlOut).to.equal(expectedXmlOut); + }); + }) }) }); diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index b2625e1..8ef918a 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -211,7 +211,7 @@ $.extend(DocumentNodeElement.prototype, { for(var i = children.length - 1; i >= 0; i--) { childParts = children[i].toXML(level + 1); - if(containsPrefixAndSuffix(i)) { + if(containsPrefixAndSuffix(i) && children[i] instanceof DocumentTextElement) { $(node.contents()[0]).after(childParts); } else { node.prepend(childParts);