JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
implement backspace key
[peach-html5-editor.git] / editor.coffee
index df8ad8a..2835af8 100644 (file)
@@ -387,6 +387,11 @@ class PeachHTML5Editor
                                        when KEY_END
                                                return false
                                        when KEY_BACKSPACE
+                                               return false unless @cursor?
+                                               return false unless @cursor[1] > 0
+                                               @cursor[0].text = @cursor[0].text.substr(0, @cursor[1] - 1) + @cursor[0].text.substr(@cursor[1])
+                                               @cursor[0].el.nodeValue = @cursor[0].text
+                                               @move_cursor [@cursor[0], @cursor[1] - 1]
                                                return false
                                        when KEY_DELETE
                                                return false