more clearly skip prints before screen top

This commit is contained in:
Kartik K. Agaram 2022-07-20 06:53:58 -07:00
parent 26ba6e4e5a
commit d41301c1b7
1 changed files with 19 additions and 21 deletions

View File

@ -31,10 +31,12 @@ function Text.draw(State, line_index, y, startpos)
local frag_len = utf8.len(frag)
--? local s=tostring
--? print('('..s(x)..','..s(y)..') '..frag..'('..s(frag_width)..' vs '..s(right)..') '..s(line_index)..' vs '..s(State.screen_top1.line)..'; '..s(pos)..' vs '..s(State.screen_top1.pos)..'; bottom: '..s(State.screen_bottom1.line)..'/'..s(State.screen_bottom1.pos))
if Text.lt1({line=line_index, pos=pos}, State.screen_top1) then
-- render nothing
--? print('skipping', frag)
else
if x + frag_width > State.right then
assert(x > State.left) -- no overfull lines
-- update y only after drawing the first screen line of screen top
if Text.lt1(State.screen_top1, {line=line_index, pos=pos}) then
y = y + State.line_height
if y + State.line_height > App.screen.height then
--? print('b', y, App.screen.height, '=>', screen_line_starting_pos)
@ -42,19 +44,14 @@ function Text.draw(State, line_index, y, startpos)
end
screen_line_starting_pos = pos
--? print('text: new screen line', y, App.screen.height, screen_line_starting_pos)
end
x = State.left
end
--? print('checking to draw', pos, State.screen_top1.pos)
-- don't draw text above screen top
if Text.le1(State.screen_top1, {line=line_index, pos=pos}) then
if State.selection1.line then
local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)
Text.draw_highlight(State, line, x,y, pos, lo,hi)
end
--? print('drawing '..frag)
App.screen.draw(frag_text, x,y)
end
-- render cursor if necessary
if line_index == State.cursor1.line then
if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then
@ -70,6 +67,7 @@ function Text.draw(State, line_index, y, startpos)
end
end
x = x + frag_width
end
pos = pos + frag_len
end
if State.search_term == nil then