diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-05-21 22:08:13 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-05-21 22:32:43 -0700 |
commit | 84898ed43a80f00f3df5acd069f808e45d85f24d (patch) | |
tree | a3d7db9dc9ddfd0008ca02225313a1382a844398 /text.lua | |
parent | 96dfe4f669eca35c77f4f2b4458bac8038a0bd84 (diff) | |
download | text.love-84898ed43a80f00f3df5acd069f808e45d85f24d.tar.gz |
bugfix: printing the first part of a line at the bottom made it seem non-wrapping
Still lots wrong here.
Diffstat (limited to 'text.lua')
-rw-r--r-- | text.lua | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/text.lua b/text.lua index 852ff94..8e99c12 100644 --- a/text.lua +++ b/text.lua @@ -28,9 +28,7 @@ function Text.draw(line, line_width, line_index) assert(x > 25) -- no overfull lines if line_index > Screen_top1.line or pos > Screen_top1.pos then y = y + math.floor(15*Zoom) - if y + math.floor(15*Zoom) > Screen_height then - return y, screen_line_starting_pos - end + if New_foo then print('text: new screen line', y, Screen_height, screen_line_starting_pos) end screen_line_starting_pos = pos if Debug_new_render then print('y', y) end end @@ -40,6 +38,11 @@ function Text.draw(line, line_width, line_index) else table.insert(line.screen_line_starting_pos, pos) end + if line_index > Screen_top1.line or pos > Screen_top1.pos then + if y + math.floor(15*Zoom) >= Screen_height then + return y, screen_line_starting_pos + end + end end if Debug_new_render then print('checking to draw', pos, Screen_top1.pos) end if line_index > Screen_top1.line or pos >= Screen_top1.pos then @@ -279,42 +282,43 @@ function Text.keychord_pressed(chord) end elseif chord == 'down' then assert(Lines[Cursor1.line].mode == 'text') + print('down', Cursor1.line, Cursor1.pos, Screen_top1.line, Screen_top1.pos, Screen_bottom1.line, Screen_bottom1.pos) if Text.cursor_at_final_screen_line() then -- line is done, skip to next text line ---? print('down: cursor at final screen line of its line') + print('cursor at final screen line of its line') +--? os.exit(1) local new_cursor_line = Cursor1.line while new_cursor_line < #Lines do new_cursor_line = new_cursor_line+1 if Lines[new_cursor_line].mode == 'text' then Cursor1.line = new_cursor_line Cursor1.pos = Text.nearest_cursor_pos(Lines[Cursor1.line].data, Cursor_x) ---? print(Cursor1.pos) + print(Cursor1.pos) break end end ---? print(Cursor1.line, Cursor1.pos, Screen_bottom1.line) if Cursor1.line > Screen_bottom1.line then ---? print('screen top before:', Screen_top1.line, Screen_top1.pos) + print('screen top before:', Screen_top1.line, Screen_top1.pos) Screen_top1.line = Cursor1.line ---? print('scroll up preserving cursor') + print('scroll up preserving cursor') Text.scroll_up_while_cursor_on_screen() ---? print('screen top after:', Screen_top1.line, Screen_top1.pos) + print('screen top after:', Screen_top1.line, Screen_top1.pos) end ---? print('=>', Cursor1.line, Cursor1.pos, Screen_bottom1.line) else -- move down one screen line in current line ---? print('cursor is NOT at final screen line of its line') + print('cursor is NOT at final screen line of its line') local screen_line_index, screen_line_starting_pos = Text.pos_at_start_of_cursor_screen_line() new_screen_line_starting_pos = Lines[Cursor1.line].screen_line_starting_pos[screen_line_index+1] ---? print('switching pos of screen line at cursor from '..tostring(screen_line_starting_pos)..' to '..tostring(new_screen_line_starting_pos)) + print('switching pos of screen line at cursor from '..tostring(screen_line_starting_pos)..' to '..tostring(new_screen_line_starting_pos)) local s = string.sub(Lines[Cursor1.line].data, new_screen_line_starting_pos) Cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, Cursor_x) - 1 ---? print('cursor pos is now '..tostring(Cursor1.pos)) + print('cursor pos is now '..tostring(Cursor1.pos)) Screen_top1.line = Cursor1.line ---? print('scroll up preserving cursor') + print('scroll up preserving cursor') Text.scroll_up_while_cursor_on_screen() ---? print('screen top after:', Screen_top1.line, Screen_top1.pos) + print('screen top after:', Screen_top1.line, Screen_top1.pos) end + print('=>', Cursor1.line, Cursor1.pos, Screen_top1.line, Screen_top1.pos, Screen_bottom1.line, Screen_bottom1.pos) end end @@ -336,6 +340,7 @@ function Text.cursor_at_final_screen_line() return true end screen_lines = Lines[Cursor1.line].screen_line_starting_pos + print(screen_lines[#screen_lines], Cursor1.pos) return screen_lines[#screen_lines] <= Cursor1.pos end @@ -358,13 +363,13 @@ function Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necess end function Text.scroll_up_while_cursor_on_screen() - local cursor_pos_screen_lines = Text.pos_at_start_of_cursor_screen_line() ---? print('cursor pos '..tostring(Cursor1.pos)..' is on the #'..tostring(cursor_pos_screen_lines)..' screen line down') - local y = Screen_height - cursor_pos_screen_lines*math.floor(15*Zoom) + local cursor2 = Text.to2(Cursor1) + print('cursor pos '..tostring(Cursor1.pos)..' is on the #'..tostring(cursor2.screen_line)..' screen line down') + local y = Screen_height - cursor2.screen_pos*math.floor(15*Zoom) -- duplicate some logic from love.draw while true do if Screen_top1.line == 1 then break end ---? print('y', y) + print('y', y) local h = 0 if Lines[Screen_top1.line-1].mode == 'drawing' then h = 20 + Drawing.pixels(Lines[Screen_top1.line-1].h) @@ -374,7 +379,7 @@ function Text.scroll_up_while_cursor_on_screen() local n = #Lines[Screen_top1.line-1].screen_line_starting_pos h = h + n*math.floor(15*Zoom) -- text height end ---? print('height:', h) + print('height:', h) if y - h < 0 then break end @@ -482,7 +487,7 @@ end function Text.to2(pos1) local result = {line=pos1.line, screen_line=1} - if Line[pos1.line].screen_line_starting_pos == nil then + if Lines[pos1.line].screen_line_starting_pos == nil then result.screen_pos = pos1.pos else for i=#Lines[pos1.line].screen_line_starting_pos,1,-1 do |