JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
implement delete key
authorJason Woofenden <jason@jasonwoof.com>
Wed, 24 Feb 2016 19:06:42 +0000 (14:06 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Wed, 24 Feb 2016 19:06:42 +0000 (14:06 -0500)
editor.coffee

index 2835af8..52ffa0c 100644 (file)
@@ -394,6 +394,11 @@ class PeachHTML5Editor
                                                @move_cursor [@cursor[0], @cursor[1] - 1]
                                                return false
                                        when KEY_DELETE
+                                               return false unless @cursor?
+                                               return false unless @cursor[1] < @cursor[0].text.length
+                                               @cursor[0].text = @cursor[0].text.substr(0, @cursor[1]) + @cursor[0].text.substr(@cursor[1] + 1)
+                                               @cursor[0].el.nodeValue = @cursor[0].text
+                                               @move_cursor [@cursor[0], @cursor[1]]
                                                return false
                                        when KEY_ENTER
                                                return false
@@ -451,7 +456,6 @@ class PeachHTML5Editor
                @clear_dom()
                instantiate_tree @tree, @idoc.body
        move_cursor: (cursor) ->
-               return if @cursor? and cursor? and @cursor[0] is cursor[0] and @cursor[1] is cursor[1]
                @cursor = cursor
                # replace cursor, to reset blink animation
                if @cursor_visible