Fixing white space handling
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 9 Jul 2013 15:31:43 +0000 (17:31 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 9 Jul 2013 15:31:43 +0000 (17:31 +0200)
modules/documentCanvas/canvas/canvas.js
modules/documentCanvas/canvas/canvas.test3.js

index ba7daef..6131e4e 100644 (file)
@@ -53,7 +53,10 @@ $.extend(Canvas.prototype, {
                                     + (endSpace && (spanParent || spanAfter) ? ' ' : '');
 
                     } else {
                                     + (endSpace && (spanParent || spanAfter) ? ' ' : '');
 
                     } else {
+                        var oldLength = this.data.length;
                         this.data = $.trim(this.data);
                         this.data = $.trim(this.data);
+                        if(this.data.length === 0 && oldLength > 0)
+                            this.data = ' ';
                     }
                 });
             
                     }
                 });
             
index 5aa4aad..77b3b19 100644 (file)
@@ -162,6 +162,7 @@ describe('Canvas', function() {
                     var c = canvas.fromXML('<section> </section>');
                     expect(c.doc().children().length).to.equal(1);
                     expect(c.doc().children()[0]).to.be.instanceOf(documentElement.DocumentTextElement);
                     var c = canvas.fromXML('<section> </section>');
                     expect(c.doc().children().length).to.equal(1);
                     expect(c.doc().children()[0]).to.be.instanceOf(documentElement.DocumentTextElement);
+                    expect(c.doc().children()[0].getText()).to.equal(' ');
                 });
                 it('ignores white space surrounding block elements', function() {
                     var c = canvas.fromXML('<section> <div></div> </section>');
                 });
                 it('ignores white space surrounding block elements', function() {
                     var c = canvas.fromXML('<section> <div></div> </section>');