From: Aleksander Ɓukasz Date: Thu, 18 Jul 2013 14:05:55 +0000 (+0200) Subject: Output formatting wip: keeping excessive white space at the end of text intact X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/d6174a70be823dd5772d845b83e11d0b779ab513?ds=sidebyside;hp=61143e615dfb903cd11c11539b7259cc4bc8b9fe Output formatting wip: keeping excessive white space at the end of text intact --- diff --git a/modules/documentCanvas/canvas/canvas.js b/modules/documentCanvas/canvas/canvas.js index 079c229..b11432f 100644 --- a/modules/documentCanvas/canvas/canvas.js +++ b/modules/documentCanvas/canvas/canvas.js @@ -65,11 +65,11 @@ $.extend(Canvas.prototype, { idx = parentContents.index(this), next = idx < parentContents.length - 1 ? parentContents[idx+1] : null; - var addInfo = function() { + var addInfo = function(toAdd) { if(next) { - $(next).data('orig-before', oldText); + $(next).data('orig-before', toAdd); } else { - parent.data('orig-append', oldText); + parent.data('orig-append', toAdd); } } @@ -82,7 +82,12 @@ $.extend(Canvas.prototype, { + (endSpace && (spanParent || spanAfter) ? ' ' : ''); if(newText !== oldText) { this.data = newText; - addInfo(); + if(endSpace) { + var toAdd = oldText.match(/\s+$/g)[0]; + if(newText[newText.length - 1] === ' ' && toAdd[0] === ' ') + toAdd = toAdd.substr(1); + addInfo(toAdd); + } } } else { @@ -90,7 +95,7 @@ $.extend(Canvas.prototype, { if(this.data.length === 0 && oldLength > 0 && el.parent().contents().length === 1) this.data = ' '; if(this.data.length === 0) { - addInfo(); + addInfo(oldText); el.remove(); return true; // continue diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index 2017a8a..e17c758 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -1173,6 +1173,21 @@ describe('Canvas', function() { expect(xmlOut).to.equal('
'); }); + it('keeps original white space at the end of text', function() { + + var xmlIn = '
Some text ended with white space \ + \ + Some text some text\ + \ +
', + c = canvas.fromXML(xmlIn); + + var xmlOut = c.toXML(); + console.log(xmlOut); + expect(xmlOut).to.equal(xmlIn); + + }); + }) }) });