diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2024-06-09 20:35:50 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2024-06-09 20:35:50 -0700 |
commit | 9b5a78d3c507a616a59e2933b061603b1e421695 (patch) | |
tree | 2851f0ffe0bd88af6cd3d4dd4cdc4d07b58c2955 /source_text.lua | |
parent | 9501f01ca0a8ddcf54e12584f79833c884fde939 (diff) | |
download | view.love-9b5a78d3c507a616a59e2933b061603b1e421695.tar.gz |
bugfix in source editor
Diffstat (limited to 'source_text.lua')
-rw-r--r-- | source_text.lua | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/source_text.lua b/source_text.lua index 7c1838c..0fced93 100644 --- a/source_text.lua +++ b/source_text.lua @@ -683,6 +683,7 @@ function Text.pos_at_start_of_screen_line(State, loc1) end function Text.pos_at_end_of_screen_line(State, loc1) + assert(State.lines[loc1.line].mode == 'text') 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 @@ -696,6 +697,24 @@ function Text.pos_at_end_of_screen_line(State, loc1) assert(false, ('invalid pos %d'):format(loc1.pos)) end +function Text.final_text_loc_on_screen(State) + if State.lines[State.screen_bottom1.line].mode == 'text' then + return { + line=State.screen_bottom1.line, + pos=Text.pos_at_end_of_screen_line(State, State.screen_bottom1), + } + end + local loc2 = Text.to2(State, State.screen_bottom1) + while true do + if State.lines[loc2.line].mode == 'text' then break end + assert(loc2.line > 1 or loc2.screen_line > 1 and loc2.screen_pos > 1) -- elsewhere we're making sure there's always at least one text line on screen + loc2 = Text.previous_screen_line(State, loc2) + end + local result = Text.to1(State, loc2) + result.pos = Text.pos_at_end_of_screen_line(State, result) + return result +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 |