From: Aleksander Ɓukasz Date: Fri, 12 Jul 2013 14:09:57 +0000 (+0200) Subject: Fixing splitting at the very beginning of a text element X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/13e2b1378fc439299f211939abeb07c732c91566?hp=3b3bcea4776b283d1a29d81bdd190778428d41e2 Fixing splitting at the very beginning of a text element --- diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index 147da86..a4e0c2e 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -332,6 +332,34 @@ describe('Canvas', function() { 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('
Some header
'), + 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('
Some header
'), + 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('\
\ diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index b82b471..e805b35 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -225,7 +225,7 @@ $.extend(DocumentTextElement.prototype, { 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);