about summary refs log tree commit diff stats
path: root/text.lua
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 /text.lua
parent7e6705a113c53bda16cf9d6ba937f79b9f98b307 (diff)
downloadview.love-ce94f8bf799342782c9ca28da850ceae452e7a41.tar.gz
another piece of support for line wrapping in cursor up
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua10
1 files changed, 9 insertions, 1 deletions
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