editor: small fix
[fnpeditor.git] / src / editor / plugins / core / lists.js
index 427673e..7a9d321 100644 (file)
@@ -45,11 +45,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
                 });
@@ -67,10 +69,18 @@ var toggleListAction = function(type) {
             toSearch.some(function(node) {
                 if(node.is('list')) {
                     node.document.transaction(function() {
-                        node.object.extractListItems();
+                        var firstItem = node.object.extractListItems(),
+                            toret;
+                        if(params.fragment.isValid()) {
+                            toret = params.fragment;
+                        } else {
+                            toret = node.document.createFragment(node.document.NodeFragment, {node: firstItem});
+                        }
+                        return toret;
                     }, {
                         metadata: {
-                            description: action.getState().description
+                            description: action.getState().description,
+                            fragment: params.fragment
                         },
                         success: callback
                     });
@@ -83,10 +93,17 @@ var toggleListAction = function(type) {
             var node = params.fragment.node,
                 action = this;
             node.document.transaction(function() {
-                node.getParent('list').setClass(type === 'Bullet' ? 'list' : 'list.enum');
+                var list = node.getParent('list');
+                list.setClass(type === 'Bullet' ? 'list' : 'list.enum');
+                if(params.fragment.isValid()) {
+                    return params.fragment;
+                } else {
+                    return node.document.createFragment(node.document.NodeFragment, {node: list.contents()[0]});
+                }
             }, {
                 metadata: {
-                    description: action.getState().description
+                    description: action.getState().description,
+                    fragment: params.fragment
                 },
                 success: callback
             });
@@ -101,6 +118,7 @@ var toggleListAction = function(type) {
         return false;
     };
 
+    var label = type === 'Bullet' ? gettext('bull. list') : gettext('num. list');
 
     return {
         name: 'toggle' + type + 'List',
@@ -109,7 +127,7 @@ var toggleListAction = function(type) {
             fragment: {type: 'context', name: 'fragment'}
         },
         stateDefaults: {
-            label: type === 'Bullet' ? gettext('bull. list') : gettext('num. list')
+            label: label
         },
         getState: function(params) {
             if(!params.fragment || !params.fragment.isValid()) {
@@ -121,7 +139,7 @@ var toggleListAction = function(type) {
                 if((list.getClass() === 'list' && type === 'Enum') || (list.getClass() === 'list.enum' && type === 'Bullet')) {
                     return {
                         allowed: true,
-                        description: interpolate(gettext('Change list type to %s'), [type]),
+                        description: interpolate(gettext('Change list type to %s'), [label]),
                         execute: execute.changeType
                     };
                 }