bugfix: search highlight straddling screen lines

This commit is contained in:
Kartik K. Agaram 2023-07-31 09:15:48 -07:00
parent 2b52383e18
commit bb3e12eb5f
2 changed files with 16 additions and 14 deletions

View File

@ -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 if not hide_cursor and line_index == State.cursor1.line then
-- render search highlight or cursor -- render search highlight or cursor
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 data = State.lines[State.cursor1.line].data local cursor_offset = Text.offset(data, State.cursor1.pos)
local cursor_offset = Text.offset(data, State.cursor1.pos) if data:sub(cursor_offset, cursor_offset+#State.search_term-1) == State.search_term then
if data:sub(cursor_offset, cursor_offset+#State.search_term-1) == State.search_term then local save_selection = State.selection1
local hi = State.cursor1.pos+utf8.len(State.search_term) State.selection1 = {line=line_index, pos=State.cursor1.pos+utf8.len(State.search_term)}
Text.draw_highlight(State, line, State.left,y, pos, State.cursor1.pos, hi) local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)
end Text.draw_highlight(State, line, State.left,y, pos, lo,hi)
State.selection1 = save_selection
end end
elseif Focus == 'edit' then elseif Focus == 'edit' then
if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then

View File

@ -30,13 +30,14 @@ function Text.draw(State, line_index, y, startpos)
if line_index == State.cursor1.line then if line_index == State.cursor1.line then
-- render search highlight or cursor -- render search highlight or cursor
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 data = State.lines[State.cursor1.line].data local cursor_offset = Text.offset(data, State.cursor1.pos)
local cursor_offset = Text.offset(data, State.cursor1.pos) if data:sub(cursor_offset, cursor_offset+#State.search_term-1) == State.search_term then
if data:sub(cursor_offset, cursor_offset+#State.search_term-1) == State.search_term then local save_selection = State.selection1
local hi = State.cursor1.pos+utf8.len(State.search_term) State.selection1 = {line=line_index, pos=State.cursor1.pos+utf8.len(State.search_term)}
Text.draw_highlight(State, line, State.left,y, pos, State.cursor1.pos, hi) local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)
end Text.draw_highlight(State, line, State.left,y, pos, lo,hi)
State.selection1 = save_selection
end end
else else
if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then