X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=editor.coffee;h=52ffa0cfaef584c06768d790648d5251e3559c46;hb=41ddb34ef4631caaa314d696e88be873b10ee884;hp=df8ad8accb7ec9036e1303a03f6ca3bcab6c8ed2;hpb=ae38e0db8cb6eba45ffb6c1a3e76c1b20efba696;p=peach-html5-editor.git diff --git a/editor.coffee b/editor.coffee index df8ad8a..52ffa0c 100644 --- a/editor.coffee +++ b/editor.coffee @@ -387,8 +387,18 @@ 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 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 @@ -446,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