editor: plugins/core - remove & type change list actions return new document fragment
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 12 May 2014 09:10:51 +0000 (11:10 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 12 May 2014 09:10:51 +0000 (11:10 +0200)
src/editor/plugins/core/lists.js

index 0c017f8..5a1b875 100644 (file)
@@ -67,7 +67,14 @@ var toggleListAction = function(type) {
             toSearch.some(function(node) {
                 if(node.is('list')) {
                     node.document.transaction(function() {
             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
                     }, {
                         metadata: {
                             description: action.getState().description
@@ -83,7 +90,13 @@ var toggleListAction = function(type) {
             var node = params.fragment.node,
                 action = this;
             node.document.transaction(function() {
             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
             }, {
                 metadata: {
                     description: action.getState().description