about summary refs log tree commit diff stats
path: root/source_text.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-07-31 08:24:15 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-07-31 08:40:07 -0700
commitf7f42b0befc3fbe6c425cfa8bad18192c2beb926 (patch)
treef130115e51beb5b0feb4b4f7d0eb9c9d5f78a9cf /source_text.lua
parent484b76f5c6984f4d3a745d9fb36dd55cefb97c06 (diff)
downloadlines.love-f7f42b0befc3fbe6c425cfa8bad18192c2beb926.tar.gz
hoist and duplicate a conditional
I'm duplicating the bounds check when drawing cursor and search
highlight because they're separate concerns and require subtly different
logic.
Diffstat (limited to 'source_text.lua')
-rw-r--r--source_text.lua8
1 files changed, 5 insertions, 3 deletions
diff --git a/source_text.lua b/source_text.lua
index b3d4963..9e3a9ac 100644
--- a/source_text.lua
+++ b/source_text.lua
@@ -53,8 +53,8 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
       end
       if not hide_cursor and line_index == State.cursor1.line then
         -- render search highlight or cursor
-        if pos <= State.cursor1.pos and pos + frag_len >= State.cursor1.pos then
-          if State.search_term then
+        if State.search_term then
+          if pos <= State.cursor1.pos and pos + frag_len >= State.cursor1.pos then
             local data = State.lines[State.cursor1.line].data
             local cursor_offset = Text.offset(data, State.cursor1.pos)
             if data:sub(cursor_offset, cursor_offset+#State.search_term-1) == State.search_term then
@@ -62,7 +62,9 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
               App.color(Text_color)
               love.graphics.print(State.search_term, State.left+lo_px,y)
             end
-          elseif Focus == 'edit' then
+          end
+        elseif Focus == 'edit' then
+          if pos <= State.cursor1.pos and pos + frag_len >= State.cursor1.pos then
             Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
           end
         end