Visual editor: hitting enter moves to a new tag - copy of current one (Chrome, FF)
[fnpeditor.git] / modules / visualEditor.js
index 73622f9..702c812 100644 (file)
@@ -31,6 +31,18 @@ rng.modules.visualEditor = function(sandbox) {
                 view._markSelected(anchor);\r
             });\r
             \r
+            this.node.on('keydown', '#rng-visualEditor-contentWrapper', function(e) {\r
+                if(e.which === 13) { \r
+                    e.preventDefault();\r
+                    var anchor = $(window.getSelection().anchorNode);\r
+                    if(anchor[0].nodeType === Node.TEXT_NODE)\r
+                        anchor = anchor.parent();\r
+                    var newNode = anchor.clone().empty();\r
+                    anchor.after(newNode);\r
+                    view.selectNode(newNode);\r
+                }\r
+            });\r
+            \r
             \r
             var metaTable = this.metaTable = this.node.find('#rng-visualEditor-meta table');\r
             \r
@@ -107,8 +119,13 @@ rng.modules.visualEditor = function(sandbox) {
             var firstNodeWithText = this.node.find('[wlxml-tag]').filter(function() {\r
                 return $(this).clone().children().remove().end().text().trim() !== '';\r
             }).first();\r
+            var node;\r
             if(firstNodeWithText.length)\r
-                this.selectNode($(firstNodeWithText[0]));\r
+                node = $(firstNodeWithText[0])\r
+            else {\r
+                node = this.node.find('[wlxml-class|="p"]')\r
+            }\r
+            this.selectNode(node);\r
         },\r
         _addMetaRow: function(key, value) {\r
             var newRow = $(sandbox.getTemplate('metaItem')({key: key || '', value: value || ''}));\r