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 09:15:48 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-07-31 09:15:48 -0700
commitbb3e12eb5fc70e815411cde7be9ace3a4b78b923 (patch)
treed1c1457fc4cc5e3f217febc0800b9436fb5394d3 /source_text.lua
parent2b52383e181e317f348b5abe734f0f484ea69121 (diff)
downloadlines.love-bb3e12eb5fc70e815411cde7be9ace3a4b78b923.tar.gz
bugfix: search highlight straddling screen lines
Diffstat (limited to 'source_text.lua')
-rw-r--r--source_text.lua15
1 files changed, 8 insertions, 7 deletions
diff --git a/source_text.lua b/source_text.lua
index d02d7d7..23d799d 100644
--- a/source_text.lua
+++ b/source_text.lua
@@ -47,13 +47,14 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
       if not hide_cursor and line_index == State.cursor1.line then
         -- render search highlight or cursor
         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
-              local hi = State.cursor1.pos+utf8.len(State.search_term)
-              Text.draw_highlight(State, line, State.left,y, pos, State.cursor1.pos, hi)
-            end
+          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
+            local save_selection = State.selection1
+            State.selection1 = {line=line_index, pos=State.cursor1.pos+utf8.len(State.search_term)}
+            local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)
+            Text.draw_highlight(State, line, State.left,y, pos, lo,hi)
+            State.selection1 = save_selection
           end
         elseif Focus == 'edit' then
           if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then