JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
replace del key hack with one that uses backspace code
authorJason Woofenden <jason@jasonwoof.com>
Wed, 25 May 2016 13:12:52 +0000 (09:12 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Wed, 25 May 2016 13:12:52 +0000 (09:12 -0400)
editor.coffee

index 36c6660..238625c 100644 (file)
@@ -952,15 +952,22 @@ class PeachHTML5Editor
                                return false
                        when KEY_DELETE
                                return false unless @cursor?
-                               return false unless @cursor.i < @cursor.n.text.length
-                               @remove_character @cursor.n, @cursor.i
-                               @text_cleanup @cursor.n
-                               @changed()
-                               new_cursor = new_cursor_position n: @cursor.n, i: @cursor.i
+                               new_cursor = find_next_cursor_position @tree, n: @cursor.n, i: @cursor.i
+                               # try moving cursor right and then running backspace code
+                               # TODO replace this hack with a real implementation
                                if new_cursor?
-                                       @move_cursor new_cursor
-                               else
-                                       @kill_cursor()
+                                       # try to detect common case where cursor goes inside an block,
+                                       # but doesn't pass a character (and advance one more in that case)
+                                       if new_cursor.n isnt @cursor.n and new_cursor.i is 0
+                                               if new_cursor.n.type is 'text' and new_cursor.n.text.length > 0
+                                                       if new_cursor.n.parent?
+                                                               unless @is_display_block new_cursor.n.parent
+                                                                       # FIXME should test run sibling
+                                                                       new_cursor = new_cursor_position n: new_cursor.n, i: new_cursor.i + 1
+                               if new_cursor?
+                                       if new_cursor.n isnt @cursor.n or new_cursor.i isnt @cursor.i
+                                               @move_cursor new_cursor
+                                               @on_key_backspace e
                                return false
                        when KEY_ENTER
                                @on_key_enter e
@@ -1159,7 +1166,7 @@ class PeachHTML5Editor
                                        @_merge_left merge_state
                                        @text_cleanup merge_state.n
                                        new_cursor = new_cursor_position n: merge_state.n, i: merge_state.i
-                               # FIXME CONTINUE
+                               # FIXME implement this:
                                # else # if prev (in run) is inline-block
                                        # if that inline-block has text in it
                                                # delete last char in prev inlineblock