Visual editor - handling double enter
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 24 Apr 2013 09:20:00 +0000 (11:20 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 24 Apr 2013 09:20:00 +0000 (11:20 +0200)
If enter is hit in empty node, the node gets deleted and
clone of it's parent is created and inserted after the original.

modules/visualEditor.js

index 77ed078..83bf329 100644 (file)
@@ -37,6 +37,11 @@ rng.modules.visualEditor = function(sandbox) {
                     var anchor = $(window.getSelection().anchorNode);\r
                     if(anchor[0].nodeType === Node.TEXT_NODE)\r
                         anchor = anchor.parent();\r
+                    if(anchor.text() === '') {\r
+                        var todel = anchor;\r
+                        anchor = anchor.parent();\r
+                        todel.remove();\r
+                    }\r
                     var newNode = anchor.clone().empty();\r
                     newNode.attr('id', '');\r
                     anchor.after(newNode);\r