about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-07-31 08:56:20 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-07-31 08:56:20 -0700
commit2b52383e181e317f348b5abe734f0f484ea69121 (patch)
tree779aa2bc9c71c00418c257fb23499ae4bda378bc
parent8879fd6f29c1c997a87afe33167d634f7294e397 (diff)
downloadtext.love-2b52383e181e317f348b5abe734f0f484ea69121.tar.gz
remove a duplicate print to screen
In addition to being more efficient, this will simplify the next bugfix.
-rw-r--r--source_text.lua20
-rw-r--r--text.lua11
2 files changed, 14 insertions, 17 deletions
diff --git a/source_text.lua b/source_text.lua
index 2c33159..d02d7d7 100644
--- a/source_text.lua
+++ b/source_text.lua
@@ -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
diff --git a/text.lua b/text.lua
index a477c4f..da97a55 100644
--- a/text.lua
+++ b/text.lua
@@ -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