bugfix: highlight search patterns on the right line
scenario: * position a wrapped line on screen * search for the word immediately after the point of wrapping Before this commit the word would be highlighted twice: - at the end of the first screen line - at the start of the second screen line Now it shows up at the right place.
This commit is contained in:
parent
f7f42b0bef
commit
d6c06db97a
|
@ -54,7 +54,7 @@ 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
|
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
|
||||||
|
@ -64,7 +64,12 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
|
||||||
end
|
end
|
||||||
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
|
||||||
|
Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
|
||||||
|
elseif pos + frag_len == State.cursor1.pos then
|
||||||
|
-- Show cursor at end of line.
|
||||||
|
-- This place also catches end of wrapping screen lines. That doesn't seem worth distinguishing.
|
||||||
|
-- It seems useful to see a cursor whether your eye is on the left or right margin.
|
||||||
Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
|
Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
9
text.lua
9
text.lua
|
@ -32,7 +32,7 @@ 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
|
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
|
||||||
|
@ -42,7 +42,12 @@ function Text.draw(State, line_index, y, startpos)
|
||||||
end
|
end
|
||||||
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
|
||||||
|
Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
|
||||||
|
elseif pos + frag_len == State.cursor1.pos then
|
||||||
|
-- Show cursor at end of line.
|
||||||
|
-- This place also catches end of wrapping screen lines. That doesn't seem worth distinguishing.
|
||||||
|
-- It seems useful to see a cursor whether your eye is on the left or right margin.
|
||||||
Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
|
Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user