Fixing canvas.createList
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 26 Jun 2013 10:32:58 +0000 (12:32 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 26 Jun 2013 10:32:58 +0000 (12:32 +0200)
Selecting text for list items from bottom to top wasn't supported

modules/documentCanvas/canvas.js
modules/documentCanvas/tests/canvas.test.js

index a6becf4..0d4ad75 100644 (file)
@@ -131,6 +131,14 @@ Canvas.prototype.createList = function(options) {
         return false;\r
         \r
     var parent = element1.parent();\r
+    \r
+    if(parent.contents().index(element1) > parent.contents().index(element2)) {\r
+        var tmp = element1;\r
+        element1 = element2;\r
+        element2 = tmp;\r
+    }\r
+        \r
+    \r
     var nodesToWrap = [];\r
     \r
     var place = 'before';\r
index 35f0d85..53bd35d 100644 (file)
@@ -137,6 +137,25 @@ define([
 \r
         });\r
         \r
+        test('create list from existing nodes reverse', function() {\r
+            var c = new canvas.Canvas('<section><div>Alice</div>has<div>a cat</div><div>some text</div></section>');\r
+            var div1 = c.getNode({tag:'div'})[0];\r
+            var div2 = c.getNode({tag:'div'})[1];\r
+            \r
+            c.createList({start: div2, end: div1});\r
+            \r
+            assert.xmlEqual(c.toXML(), '\\r
+                <section>\\r
+                    <div class="list.items">\\r
+                        <div class="item">Alice</div>\\r
+                        <div class="item">has</div>\\r
+                        <div class="item">a cat</div>\\r
+                    </div>\\r
+                    <div>some text</div>\\r
+                </section>');\r
+\r
+        });\r
+        \r
         test('remove list', function() {\r
             var xml = '\\r
                 <section>\\r