JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
start on cursor-up key
authorJason Woofenden <jason@jasonwoof.com>
Thu, 17 Mar 2016 20:58:17 +0000 (16:58 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 17 Mar 2016 20:58:17 +0000 (16:58 -0400)
editor.coffee

index d3b428a..411072a 100644 (file)
@@ -741,6 +741,27 @@ class PeachHTML5Editor
                                                        break
                                return false
                        when KEY_UP
+                               if @cursor?
+                                       new_cursor = @cursor
+                                       old_loc = cursor_to_xyh new_cursor[0], new_cursor[1]
+                                       new_loc = x: old_loc.x, y: old_loc.y
+                                       while new_loc.y >= old_loc.y
+                                               new_cursor = find_prev_cursor_position @tree, new_cursor[0], new_cursor[1]
+                                               return false unless new_cursor?
+                                               new_loc = cursor_to_xyh new_cursor[0], new_cursor[1]
+                                       if new_cursor?
+                                               # now we're above
+                                               if new_loc.x > old_loc.x
+                                                       console.log 'fixme'
+                                                       # TODO move left until we go up or meet/pass old_loc.x
+                                                       # then set new_cursor to the closest
+                                               @move_cursor new_cursor
+                               else
+                                       # move cursor to first position in document
+                                       new_cursor = find_prev_cursor_position @tree
+                                       if new_cursor?
+                                               @move_cursor new_cursor
+                                               break
                                return false
                        when KEY_RIGHT
                                if @cursor?
@@ -748,11 +769,11 @@ class PeachHTML5Editor
                                        if new_cursor?
                                                @move_cursor new_cursor
                                else
-                                       for c in @tree
-                                               new_cursor = find_prev_cursor_position @tree, c, -1
-                                               if new_cursor?
-                                                       @move_cursor new_cursor
-                                                       break
+                                       # move cursor to first position in document
+                                       new_cursor = find_prev_cursor_position @tree
+                                       if new_cursor?
+                                               @move_cursor new_cursor
+                                               break
                                return false
                        when KEY_DOWN
                                return false