more precise search highlighting
This commit is contained in:
parent
1bdb931575
commit
e2696fcc72
|
@ -51,6 +51,8 @@ function Text.clip_selection(line_index, apos, bpos)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- draw highlight for line corresponding to (lo,hi) given an approximate x,y and pos on the same screen line
|
-- draw highlight for line corresponding to (lo,hi) given an approximate x,y and pos on the same screen line
|
||||||
|
-- Creates text objects every time, so use this sparingly.
|
||||||
|
-- Returns some intermediate computation useful elsewhere.
|
||||||
function Text.draw_highlight(line, x,y, pos, lo,hi)
|
function Text.draw_highlight(line, x,y, pos, lo,hi)
|
||||||
if lo then
|
if lo then
|
||||||
local lo_offset = utf8.offset(line.data, lo)
|
local lo_offset = utf8.offset(line.data, lo)
|
||||||
|
@ -71,6 +73,7 @@ function Text.draw_highlight(line, x,y, pos, lo,hi)
|
||||||
love.graphics.setColor(0.7,0.7,0.9)
|
love.graphics.setColor(0.7,0.7,0.9)
|
||||||
love.graphics.rectangle('fill', x+lo_px,y, text_width,Line_height)
|
love.graphics.rectangle('fill', x+lo_px,y, text_width,Line_height)
|
||||||
love.graphics.setColor(0,0,0)
|
love.graphics.setColor(0,0,0)
|
||||||
|
return lo_px
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
8
text.lua
8
text.lua
|
@ -62,13 +62,9 @@ function Text.draw(line, line_width, line_index)
|
||||||
if pos <= Cursor1.pos and pos + frag_len > Cursor1.pos then
|
if pos <= Cursor1.pos and pos + frag_len > Cursor1.pos then
|
||||||
if Search_term then
|
if Search_term then
|
||||||
if Lines[Cursor1.line].data:sub(Cursor1.pos, Cursor1.pos+utf8.len(Search_term)-1) == Search_term then
|
if Lines[Cursor1.line].data:sub(Cursor1.pos, Cursor1.pos+utf8.len(Search_term)-1) == Search_term then
|
||||||
if Search_text == nil then
|
local lo_px = Text.draw_highlight(line, x,y, pos, Cursor1.pos, Cursor1.pos+utf8.len(Search_term))
|
||||||
Search_text = App.newText(love.graphics.getFont(), Search_term)
|
|
||||||
end
|
|
||||||
love.graphics.setColor(0.7,1,1)
|
|
||||||
love.graphics.rectangle('fill', x,y, App.width(Search_text),Line_height)
|
|
||||||
love.graphics.setColor(0,0,0)
|
love.graphics.setColor(0,0,0)
|
||||||
love.graphics.print(Search_term, x,y)
|
love.graphics.print(Search_term, x+lo_px,y)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Text.draw_cursor(x+Text.x(frag, Cursor1.pos-pos+1), y)
|
Text.draw_cursor(x+Text.x(frag, Cursor1.pos-pos+1), y)
|
||||||
|
|
Loading…
Reference in New Issue