diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-07-01 10:30:52 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-07-01 11:01:20 -0700 |
commit | e839c3036a24eee998fa2c7e1a47ac4d53a2b089 (patch) | |
tree | e528419df676db7fd346fd8fb498c0e7837f5f99 /text.lua | |
parent | 37c5ab87ece90f9f64b3726fcfdf20240aa7d55f (diff) | |
download | text.love-e839c3036a24eee998fa2c7e1a47ac4d53a2b089.tar.gz |
bugfix: manage screen_top and cursor when resizing
Diffstat (limited to 'text.lua')
-rw-r--r-- | text.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/text.lua b/text.lua index 8765798..7307056 100644 --- a/text.lua +++ b/text.lua @@ -915,6 +915,41 @@ function Text.populate_screen_line_starting_pos(line_index) end end +function Text.tweak_screen_top_and_cursor() +--? print('a', Selection1.line) + if Screen_top1.pos == 1 then return end + Text.populate_screen_line_starting_pos(Screen_top1.line) + local line = Lines[Screen_top1.line] + for i=2,#line.screen_line_starting_pos do + local pos = line.screen_line_starting_pos[i] + if pos == Screen_top1.pos then + break + end + if pos > Screen_top1.pos then + -- make sure screen top is at start of a screen line + local prev = line.screen_line_starting_pos[i-1] + if Screen_top1.pos - prev < pos - Screen_top1.pos then + Screen_top1.pos = prev + else + Screen_top1.pos = pos + end + break + end + end + -- make sure cursor is on screen + if Text.lt1(Cursor1, Screen_top1) then + Cursor1 = {line=Screen_top1.line, pos=Screen_top1.pos} + elseif Cursor1.line >= Screen_bottom1.line then +--? print('too low') + App.draw() + if Text.lt1(Screen_bottom1, Cursor1) then +--? print('tweak') + local line = Lines[Screen_bottom1.line] + Cursor1 = {line=Screen_bottom1.line, pos=Text.to_pos_on_line(line, App.screen.width-5, App.screen.height-5)} + end + end +end + function Text.redraw_all() --? print('clearing fragments') for _,line in ipairs(Lines) do |