From 35a137765b59206318bffecca43a478f4aba6a33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 26 Jun 2013 12:32:58 +0200 Subject: [PATCH] Fixing canvas.createList Selecting text for list items from bottom to top wasn't supported --- modules/documentCanvas/canvas.js | 8 ++++++++ modules/documentCanvas/tests/canvas.test.js | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) 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 = '\
\ -- 2.20.1