editor: return fragments from actions, set this fragment on canvas if possible
[fnpeditor.git] / src / editor / plugins / core / lists.js
index a8dc802..427673e 100644 (file)
@@ -32,7 +32,7 @@ var countItems = function(boundries) {
 var toggleListAction = function(type) {
     
     var execute = {
-        add: function(params) {
+        add: function(callback, params) {
             var boundries = getBoundriesForAList(params.fragment),
                 listParams = {klass: type === 'Bullet' ? 'list' : 'list.enum'},
                 action = this;
@@ -41,17 +41,23 @@ var toggleListAction = function(type) {
                 listParams.node1 = boundries.node1;
                 listParams.node2 = boundries.node2;
                 boundries.node1.document.transaction(function() {
-                    boundries.node1.document.createList(listParams);
+                    var list = boundries.node1.document.createList(listParams),
+                        item1 = list.object.getItem(0),
+                        text = item1 ? item1.contents()[0] : undefined, //
+                        doc = boundries.node1.document;
+
+                   return doc.createFragment(doc.CaretFragment, {node: text, offset:0});
                 }, {
                     metadata: {
                         description: action.getState().description
-                    }
+                    },
+                    success: callback
                 });
             } else {
                 throw new Error('Invalid boundries');
             }
         },
-        remove: function(params) {
+        remove: function(callback, params) {
             /* globals Node */
             var current = params.fragment.node,
                 action = this;
@@ -65,14 +71,15 @@ var toggleListAction = function(type) {
                     }, {
                         metadata: {
                             description: action.getState().description
-                        }
+                        },
+                        success: callback
                     });
                     
                     return true; // break
                 }
             }.bind(this));
         },
-        changeType: function(params) {
+        changeType: function(callback, params) {
             var node = params.fragment.node,
                 action = this;
             node.document.transaction(function() {
@@ -80,7 +87,8 @@ var toggleListAction = function(type) {
             }, {
                 metadata: {
                     description: action.getState().description
-                }
+                },
+                success: callback
             });
         }
     };