about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-06-04 12:20:24 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-06-04 12:20:24 -0700
commit9656e137742eb442e9ce013dd3f25cf6df8c9fad (patch)
treed4ab8fedbd004dc855192d52bf5908f848196dbc /text.lua
parentcf0ba7c15431221e90f6aee87ea5b69ef0b18ea4 (diff)
downloadlines.love-9656e137742eb442e9ce013dd3f25cf6df8c9fad.tar.gz
bugfix: inscript's bug
To fix this I have to first stop incrementally updating screen_bottom1
in the middle of a frame. Now it always has a good value from the end of
a frame.

I'm also running into some limitations in the test I'd ideally like to
write (that are documented in a comment), but I still get some sort of
automated test for this bugfix.
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/text.lua b/text.lua
index b6389e4..d89fb63 100644
--- a/text.lua
+++ b/text.lua
@@ -591,6 +591,7 @@ function Text.right_without_scroll(State)
   end
 end
 
+-- result: pos, index of screen line
 function Text.pos_at_start_of_screen_line(State, loc1)
   Text.populate_screen_line_starting_pos(State, loc1.line)
   local line_cache = State.line_cache[loc1.line]
@@ -603,6 +604,20 @@ function Text.pos_at_start_of_screen_line(State, loc1)
   assert(false)
 end
 
+function Text.pos_at_end_of_screen_line(State, loc1)
+  Text.populate_screen_line_starting_pos(State, loc1.line)
+  local line_cache = State.line_cache[loc1.line]
+  local most_recent_final_pos = utf8.len(State.lines[loc1.line].data)+1
+  for i=#line_cache.screen_line_starting_pos,1,-1 do
+    local spos = line_cache.screen_line_starting_pos[i]
+    if spos <= loc1.pos then
+      return most_recent_final_pos
+    end
+    most_recent_final_pos = spos-1
+  end
+  assert(false)
+end
+
 function Text.cursor_at_final_screen_line(State)
   Text.populate_screen_line_starting_pos(State, State.cursor1.line)
   local screen_lines = State.line_cache[State.cursor1.line].screen_line_starting_pos