editor: canvas - enter on an empty last list item creates paragraph after list
[fnpeditor.git] / src / editor / modules / documentCanvas / canvas / keyboard.js
index 3a90a90..7ae6b27 100644 (file)
@@ -282,7 +282,7 @@ var keyEventHandlers = [
         },
         run: function(e,s) {
             e.preventDefault();
-            e.element.wlxmlNode.setText('');
+            s.element.wlxmlNode.setText('');
             s.canvas.setCurrentElement(s.element, {caretTo: 0});
         }
     },
@@ -348,6 +348,29 @@ var keyEventHandlers = [
 
         }
     },
+    {
+        applies: function(e, s) {
+            var parent = s.element && s.element.wlxmlNode.parent(),
+                parentIsItem = parent && parent.is('item'),
+                itemIsOnList = parent && parent.parent() && parent.parent().is('list');
+            return s.type === 'caret' && e.key === KEYS.ENTER && s.element.isEmpty() && parentIsItem && itemIsOnList;
+        },
+        run: function(e, s) {
+            var item = s.element.wlxmlNode.parent(),
+                list = item.parent();
+            e.preventDefault();
+            s.canvas.wlxmlDocument.transaction(function() {
+                var p = list.after({tagName: 'div', attrs: {'class': 'p'}});
+                p.append({text: ''});
+                item.detach();
+                return p;
+            }, {
+                success: function(p) {
+                    s.canvas.setCurrentElement(p);
+                }
+            });
+        }
+    },
     {
         applies: function(e, s) {
             return s.type === 'caret' && e.key === KEYS.ENTER && !s.element.parent().isRootElement();