From: Jason Woofenden Date: Wed, 24 Feb 2016 19:06:42 +0000 (-0500) Subject: implement delete key X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-html5-editor.git;a=commitdiff_plain;h=41ddb34ef4631caaa314d696e88be873b10ee884 implement delete key --- diff --git a/editor.coffee b/editor.coffee index 2835af8..52ffa0c 100644 --- a/editor.coffee +++ b/editor.coffee @@ -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