shuffle answers in exercise order + fix answer numbering
[fnpeditor.git] / src / editor / plugins / core / lists.js
index 5a1b875..65b6e69 100644 (file)
@@ -8,10 +8,14 @@ var getBoundriesForAList = function(fragment) {
     var node;
 
     if(fragment instanceof fragment.RangeFragment && fragment.hasSiblingBoundries()) {
-        return fragment.boundriesSiblingParents();
+        return fragment.startNode.hasSameContextRoot(fragment.endNode) && fragment.boundriesSiblingParents();
     }
     if(fragment instanceof fragment.NodeFragment) {
         node = fragment.node.getNearestElementNode();
+        if(node.isContextRoot()) {
+            node = fragment.node;
+        }
+
         return {
             node1: node,
             node2: node
@@ -45,11 +49,13 @@ var toggleListAction = function(type) {
                         item1 = list.object.getItem(0),
                         text = item1 ? item1.contents()[0] : undefined, //
                         doc = boundries.node1.document;
-
-                   return doc.createFragment(doc.CaretFragment, {node: text, offset:0});
+                    if(text) {
+                        return doc.createFragment(doc.CaretFragment, {node: text, offset:0});
+                    }
                 }, {
                     metadata: {
-                        description: action.getState().description
+                        description: action.getState().description,
+                        fragment: params.fragment
                     },
                     success: callback
                 });
@@ -77,7 +83,8 @@ var toggleListAction = function(type) {
                         return toret;
                     }, {
                         metadata: {
-                            description: action.getState().description
+                            description: action.getState().description,
+                            fragment: params.fragment
                         },
                         success: callback
                     });
@@ -99,7 +106,8 @@ var toggleListAction = function(type) {
                 }
             }, {
                 metadata: {
-                    description: action.getState().description
+                    description: action.getState().description,
+                    fragment: params.fragment
                 },
                 success: callback
             });
@@ -148,7 +156,7 @@ var toggleListAction = function(type) {
 
             }
             var boundries = getBoundriesForAList(params.fragment);
-            if(boundries) {
+            if(boundries && boundries.node1.hasSameContextRoot(boundries.node2)) {
                 return {
                     allowed: true,
                     description: interpolate(gettext('Make %s fragment(s) into list'), [countItems(getBoundriesForAList(params.fragment))]),