From 9656e137742eb442e9ce013dd3f25cf6df8c9fad Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 4 Jun 2023 12:20:24 -0700 Subject: 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. --- text.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'text.lua') 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 -- cgit 1.4.1-2-gfad0