From: Aleksander Ɓukasz Date: Wed, 26 Jun 2013 10:32:58 +0000 (+0200) Subject: Fixing canvas.createList X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/35a137765b59206318bffecca43a478f4aba6a33?ds=inline;hp=f21a91b10cced1d0fd3be6b183bc64303e7f4f94 Fixing canvas.createList Selecting text for list items from bottom to top wasn't supported --- diff --git a/modules/documentCanvas/canvas.js b/modules/documentCanvas/canvas.js index a6becf4..0d4ad75 100644 --- a/modules/documentCanvas/canvas.js +++ b/modules/documentCanvas/canvas.js @@ -131,6 +131,14 @@ Canvas.prototype.createList = function(options) { return false; var parent = element1.parent(); + + if(parent.contents().index(element1) > parent.contents().index(element2)) { + var tmp = element1; + element1 = element2; + element2 = tmp; + } + + var nodesToWrap = []; var place = 'before'; diff --git a/modules/documentCanvas/tests/canvas.test.js b/modules/documentCanvas/tests/canvas.test.js index 35f0d85..53bd35d 100644 --- a/modules/documentCanvas/tests/canvas.test.js +++ b/modules/documentCanvas/tests/canvas.test.js @@ -137,6 +137,25 @@ define([ }); + test('create list from existing nodes reverse', function() { + var c = new canvas.Canvas('
Alice
has
a cat
some text
'); + var div1 = c.getNode({tag:'div'})[0]; + var div2 = c.getNode({tag:'div'})[1]; + + c.createList({start: div2, end: div1}); + + assert.xmlEqual(c.toXML(), '\ +
\ +
\ +
Alice
\ +
has
\ +
a cat
\ +
\ +
some text
\ +
'); + + }); + test('remove list', function() { var xml = '\
\