Fixing splitting at the very beginning of a text element
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 12 Jul 2013 14:09:57 +0000 (16:09 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 12 Jul 2013 14:09:57 +0000 (16:09 +0200)
modules/documentCanvas/canvas/canvas.test3.js
modules/documentCanvas/canvas/documentElement.js

index 147da86..a4e0c2e 100644 (file)
@@ -332,6 +332,34 @@ describe('Canvas', function() {
                     expect(header2.children()[0].getText()).to.equal('header', 'second header has correct content');
                 });
 
                     expect(header2.children()[0].getText()).to.equal('header', 'second header has correct content');
                 });
 
+                it('leaves empty copy of DocumentNodeElement if splitting at the very beginning', function() {
+                        var c = canvas.fromXML('<section><header>Some header</header></section>'),
+                        section = c.doc(),
+                        text = section.children()[0].children()[0];
+
+                        text.split({offset: 0});
+                        
+                        var header1 = section.children()[0];
+                        var header2 = section.children()[1];
+
+                        expect(header1.children().length).to.equal(0);
+                        expect(header2.children()[0].getText()).to.equal('Some header');
+                });
+
+                it('leaves empty copy of DocumentNodeElement if splitting at the very end', function() {
+                        var c = canvas.fromXML('<section><header>Some header</header></section>'),
+                        section = c.doc(),
+                        text = section.children()[0].children()[0];
+
+                        text.split({offset: 11});
+                        
+                        var header1 = section.children()[0];
+                        var header2 = section.children()[1];
+
+                        expect(header1.children()[0].getText()).to.equal('Some header');
+                        expect(header2.children().length).to.equal(0);
+                });
+
                 it('keeps DocumentTextElement\'s parent\'s children elements intact', function() {
                     var c = canvas.fromXML('\
                             <section>\
                 it('keeps DocumentTextElement\'s parent\'s children elements intact', function() {
                     var c = canvas.fromXML('\
                             <section>\
index b82b471..e805b35 100644 (file)
@@ -225,7 +225,7 @@ $.extend(DocumentTextElement.prototype, {
         if(prefix.length > 0)
             this.setText(prefix);
         else
         if(prefix.length > 0)
             this.setText(prefix);
         else
-            this.remove();
+            this.detach();
         
         var newElement = DocumentNodeElement.create({tag: parentElement.wlxmlTag, klass: parentElement.wlxmlClass}, myCanvas);
         parentElement.after(newElement);
         
         var newElement = DocumentNodeElement.create({tag: parentElement.wlxmlTag, klass: parentElement.wlxmlClass}, myCanvas);
         parentElement.after(newElement);