about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-20 15:19:43 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-20 15:19:43 -0700
commitce94f8bf799342782c9ca28da850ceae452e7a41 (patch)
tree3efe59d6fddadc1e169145fd95eee75abb4db4f5
parent7e6705a113c53bda16cf9d6ba937f79b9f98b307 (diff)
downloadview.love-ce94f8bf799342782c9ca28da850ceae452e7a41.tar.gz
another piece of support for line wrapping in cursor up
-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