From 7933708e8875761cdaaa5c2fd746ad4b8aa7ce3a Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Fri, 18 Mar 2016 00:06:32 -0400 Subject: [PATCH] implement real up-arrow key --- editor.coffee | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/editor.coffee b/editor.coffee index 411072a..9b4ad4f 100644 --- a/editor.coffee +++ b/editor.coffee @@ -751,11 +751,31 @@ class PeachHTML5Editor 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 + if new_loc.x <= old_loc.x + @move_cursor new_cursor + return false + target_y = new_loc.y + # search leftward, until we find the closest position + while new_loc.x > old_loc.x and new_loc.y is target_y + prev_loc = new_loc + prev_cursor = new_cursor + new_cursor = find_prev_cursor_position @tree, new_cursor[0], new_cursor[1] + break unless new_cursor? + new_loc = cursor_to_xyh new_cursor[0], new_cursor[1] + # move cursor to prev_cursor or new_cursor + if new_cursor? + if new_loc.y is target_y + # both valid, and on the same line, use closest + if (old_loc.x - new_loc.x) < (prev_loc.x - old_loc.x) + @move_cursor new_cursor + else + @move_cursor prev_cursor + else + # new_cursor on wrong line, use prev_cursor + @move_cursor prev_cursor + else + # can't go any further prev, use prev_cursor + @move_cursor prev_cursor else # move cursor to first position in document new_cursor = find_prev_cursor_position @tree -- 1.7.10.4