diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-07-31 09:15:48 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-07-31 09:15:48 -0700 |
commit | bb3e12eb5fc70e815411cde7be9ace3a4b78b923 (patch) | |
tree | d1c1457fc4cc5e3f217febc0800b9436fb5394d3 | |
parent | 2b52383e181e317f348b5abe734f0f484ea69121 (diff) | |
download | text.love-bb3e12eb5fc70e815411cde7be9ace3a4b78b923.tar.gz |
bugfix: search highlight straddling screen lines
-rw-r--r-- | source_text.lua | 15 | ||||
-rw-r--r-- | text.lua | 15 |
2 files changed, 16 insertions, 14 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 diff --git a/text.lua b/text.lua index da97a55..3323af6 100644 --- a/text.lua +++ b/text.lua @@ -30,13 +30,14 @@ function Text.draw(State, line_index, y, startpos) if 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 else if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then |