remove a duplicate print to screen

In addition to being more efficient, this will simplify the next bugfix.
This commit is contained in:
Kartik K. Agaram 2023-07-31 08:56:20 -07:00
parent 8879fd6f29
commit 2b52383e18
2 changed files with 14 additions and 17 deletions

View File

@ -39,18 +39,11 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
})
end
end
-- render fragment
-- render any highlights
if State.selection1.line then
local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)
Text.draw_highlight(State, line, State.left,y, pos, lo,hi)
end
-- render colorized text
local x = State.left
for frag in screen_line:gmatch('%S*%s*') do
select_color(frag)
App.screen.print(frag, x,y)
x = x+App.width(frag)
end
if not hide_cursor and line_index == State.cursor1.line then
-- render search highlight or cursor
if State.search_term then
@ -59,9 +52,7 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
local cursor_offset = Text.offset(data, State.cursor1.pos)
if data:sub(cursor_offset, cursor_offset+#State.search_term-1) == State.search_term then
local hi = State.cursor1.pos+utf8.len(State.search_term)
local lo_px = Text.draw_highlight(State, line, State.left,y, pos, State.cursor1.pos, hi)
App.color(Text_color)
love.graphics.print(State.search_term, State.left+lo_px,y)
Text.draw_highlight(State, line, State.left,y, pos, State.cursor1.pos, hi)
end
end
elseif Focus == 'edit' then
@ -75,6 +66,13 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
end
end
end
-- render colorized text
local x = State.left
for frag in screen_line:gmatch('%S*%s*') do
select_color(frag)
App.screen.print(frag, x,y)
x = x+App.width(frag)
end
y = y + State.line_height
if y >= App.screen.height then
break

View File

@ -22,13 +22,11 @@ function Text.draw(State, line_index, y, startpos)
local screen_line = Text.screen_line(line, line_cache, i)
--? print('text.draw:', screen_line, 'at', line_index,pos, 'after', x,y)
local frag_len = utf8.len(screen_line)
-- render fragment
-- render any highlights
if State.selection1.line then
local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)
Text.draw_highlight(State, line, State.left,y, pos, lo,hi)
end
App.color(Text_color)
App.screen.print(screen_line, State.left,y)
if line_index == State.cursor1.line then
-- render search highlight or cursor
if State.search_term then
@ -37,9 +35,7 @@ function Text.draw(State, line_index, y, startpos)
local cursor_offset = Text.offset(data, State.cursor1.pos)
if data:sub(cursor_offset, cursor_offset+#State.search_term-1) == State.search_term then
local hi = State.cursor1.pos+utf8.len(State.search_term)
local lo_px = Text.draw_highlight(State, line, State.left,y, pos, State.cursor1.pos, hi)
App.color(Text_color)
love.graphics.print(State.search_term, State.left+lo_px,y)
Text.draw_highlight(State, line, State.left,y, pos, State.cursor1.pos, hi)
end
end
else
@ -53,6 +49,9 @@ function Text.draw(State, line_index, y, startpos)
end
end
end
-- render fragment
App.color(Text_color)
App.screen.print(screen_line, State.left,y)
y = y + State.line_height
if y >= App.screen.height then
break