Preventing browser from removing node when last character gets deleted via backspace
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 19 Jun 2013 07:34:41 +0000 (09:34 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 19 Jun 2013 07:34:41 +0000 (09:34 +0200)
modules/documentCanvas/documentCanvas.js

index bb8ad4a..4e61b88 100644 (file)
@@ -51,6 +51,15 @@ return function(sandbox) {
                     e.preventDefault();\r
                     view.insertNewNode(null, null);\r
                 }\r
                     e.preventDefault();\r
                     view.insertNewNode(null, null);\r
                 }\r
+                if(e.which === 8) {\r
+                    var anchor = window.getSelection().anchorNode;\r
+                    var len = anchor.length;\r
+                    console.log(len);\r
+                    if(len === 1) {\r
+                        e.preventDefault();\r
+                        $(anchor).parent().text('');\r
+                    }\r
+                }\r
             });\r
                       \r
             this.node.onShow = function() {\r
             });\r
                       \r
             this.node.onShow = function() {\r