From cb97894506c25210fd9267397023c3adfb312a2c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 1 Jul 2013 12:10:24 +0200 Subject: [PATCH 1/1] Fix: Removing list with nested lists properly --- modules/documentCanvas/canvas.js | 15 +++++++++- modules/documentCanvas/tests/canvas.test.js | 32 +++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/modules/documentCanvas/canvas.js b/modules/documentCanvas/canvas.js index 9c926e9..b4b9c29 100644 --- a/modules/documentCanvas/canvas.js +++ b/modules/documentCanvas/canvas.js @@ -204,20 +204,33 @@ Canvas.prototype.listRemove = function(options) { var listElement = options.pointer.getClass() === 'list-items' ? pointerElement : pointerElement.parents('[wlxml-class|="list-items"][wlxml-tag]'); - var nested = false; + var nested = false, + nestedLists; if(listElement.length > 1) { listElement = $(listElement[0]); nested = true; } if(nested) { + // We are only moving one level up listElement.unwrap(); } else { + // We are removing the whole list + nestedLists = listElement.find('[wlxml-class=item] > [wlxml-class|=list-items]'); + nestedLists.unwrap(); listElement.find('[wlxml-class=item]').each(function() { $(this).removeAttr('wlxml-class'); }); } + listElement.children().unwrap(); + + var c = this; + if(nestedLists) { + nestedLists.each(function() { + c.listRemove({pointer: canvasNode.create($(this))}); + }); + } }; Canvas.prototype.getPrecedingNode = function(options) { diff --git a/modules/documentCanvas/tests/canvas.test.js b/modules/documentCanvas/tests/canvas.test.js index a9ed767..53f4aee 100644 --- a/modules/documentCanvas/tests/canvas.test.js +++ b/modules/documentCanvas/tests/canvas.test.js @@ -260,6 +260,38 @@ define([ ')); + }); + + test('removing list containing nested list', function() { + var nestedList = utils.cleanUp('\ +
\ +
\ +
alice
\ +
\ +
\ +
cat
\ +
dog
\ +
\ +
\ +
bee
\ +
\ +
'); + + var c = canvas.create(nestedList); + var alice_item = c.findNodes('[wlxml-class=list-items] > div')[0]; + assert.equal(alice_item.getContent(), 'alice'); + + c.listRemove({pointer: alice_item}); + + assertDomEqual(c.getContent(), utils.cleanUp('\ +
\ +
alice
\ +
cat
\ +
dog
\ +
bee
\ +
')); + + }); }); }); \ No newline at end of file -- 2.20.1