about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--manual_tests1
-rw-r--r--text.lua10
2 files changed, 10 insertions, 1 deletions
diff --git a/manual_tests b/manual_tests
index 1f589fc..bdb35db 100644
--- a/manual_tests
+++ b/manual_tests
@@ -23,5 +23,6 @@ scrolling:
   cursor remains on text line
   'up' arrow with cursor at top of screen scrolls up one line (drawings still fully in or out)
     if top line wrapped before, it scrolls up by only one screen line
+    if previous line (above top of screen) wrapped, it scrolls up by only one screen line
   'down' arrow with cursor at bottom of screen scrolls down one line (drawings still fully in or out)
     if top line wrapped before, it scrolls down by only one screen line
diff --git a/text.lua b/text.lua
index afe2ea5..f0c8dfe 100644
--- a/text.lua
+++ b/text.lua
@@ -227,7 +227,15 @@ function Text.keychord_pressed(chord)
         if Lines[new_cursor_line].mode == 'text' then
           local old_x = Text.cursor_x(Lines[new_cursor_line].data, Cursor_pos)
           Cursor_line = new_cursor_line
-          Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x)
+          if Lines[Cursor_line].screen_line_starting_pos == nil then
+            Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x)
+            break
+          end
+          local screen_line_starting_pos = Lines[Cursor_line].screen_line_starting_pos
+          screen_line_starting_pos = screen_line_starting_pos[#screen_line_starting_pos]
+          Top_screen_line_starting_pos = screen_line_starting_pos
+          local s = string.sub(Lines[Cursor_line].data, screen_line_starting_pos)
+          Cursor_pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, old_x) - 1
           break
         end
       end