From: Aleksander Ɓukasz Date: Thu, 11 Jul 2013 10:38:21 +0000 (+0200) Subject: Fixing list creation X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/b8a8cc88e8c86aa06660cc12fe289524bc31c48b Fixing list creation - Array.forEach has no elegant way of breaking from it, so we use Array.some instead - checking if iterating over params.element2 was failing on text elements --- diff --git a/modules/documentCanvas/canvas/canvas.js b/modules/documentCanvas/canvas/canvas.js index ee0a174..462c305 100644 --- a/modules/documentCanvas/canvas/canvas.js +++ b/modules/documentCanvas/canvas/canvas.js @@ -135,7 +135,8 @@ $.extend(Canvas.prototype.list, { var place = 'before'; var canvas = this; - parent.children().forEach(function(element) { + parent.children().some(function(element) { + var _e = element; if(element.sameNode(params.element1)) place = 'inside'; if(place === 'inside') { @@ -147,8 +148,8 @@ $.extend(Canvas.prototype.list, { element.setWlxmlClass('item'); elementsToWrap.push(element); } - if(element.sameNode(params.element2)) - return false; + if(_e.sameNode(params.element2)) + return true; }); var listElement = documentElement.DocumentNodeElement.create({tag: 'div', klass: 'list-items' + (params.type === 'enum' ? '-enum' : '')}); diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index ba14af7..609a36b 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -451,19 +451,24 @@ describe('Canvas', function() {
cat
\ '), section = c.doc(), - textAlice = section.children()[0], - divCat = section.children()[3] + textHas = section.children()[1], + divA = section.children()[2] - c.list.create({element1: textAlice, element2: divCat}); + c.list.create({element1: textHas, element2: divA}); - expect(section.children().length).to.equal(1, 'section has one child element'); + expect(section.children().length).to.equal(3, 'section has three child elements'); - var list = section.children()[0]; - expect(list.is('list')).to.equal(true, 'section\'s only child is a list'); - expect(list.children().length).to.equal(4, 'list contains four elements'); + var child1 = section.children()[0], + list = section.children()[1], + child3 = section.children()[2]; + + expect(child1.getText()).to.equal('Alice'); + expect(list.is('list')).to.equal(true, 'second child is a list'); + expect(list.children().length).to.equal(2, 'list contains two elements'); list.children().forEach(function(child) { expect(child.getWlxmlClass()).to.equal('item', 'list childs have wlxml class of item'); }); + expect(child3.children()[0].getText()).to.equal('cat'); }); describe('extracting list items', function() {