search: transparently handle drawings everywhere
This commit is contained in:
parent
e85a7e73d0
commit
8b880f4fe8
40
search.lua
40
search.lua
|
@ -20,33 +20,26 @@ function Text.draw_search_bar(State)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Text.search_next(State)
|
function Text.search_next(State)
|
||||||
local pos
|
|
||||||
-- search current line from cursor
|
-- search current line from cursor
|
||||||
local line = State.lines[State.cursor1.line]
|
local pos = find(State.lines[State.cursor1.line].data, State.search_term, State.cursor1.pos)
|
||||||
if line.mode == 'text' then
|
if pos then
|
||||||
pos = line.data:find(State.search_term, State.cursor1.pos)
|
State.cursor1.pos = pos
|
||||||
if pos then
|
|
||||||
State.cursor1.pos = pos
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if pos == nil then
|
if pos == nil then
|
||||||
-- search lines below cursor
|
-- search lines below cursor
|
||||||
for i=State.cursor1.line+1,#State.lines do
|
for i=State.cursor1.line+1,#State.lines do
|
||||||
local line = State.lines[i]
|
pos = find(State.lines[i].data, State.search_term)
|
||||||
if line.mode == 'text' then
|
if pos then
|
||||||
pos = State.lines[i].data:find(State.search_term)
|
State.cursor1.line = i
|
||||||
if pos then
|
State.cursor1.pos = pos
|
||||||
State.cursor1.line = i
|
break
|
||||||
State.cursor1.pos = pos
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if pos == nil then
|
if pos == nil then
|
||||||
-- wrap around
|
-- wrap around
|
||||||
for i=1,State.cursor1.line-1 do
|
for i=1,State.cursor1.line-1 do
|
||||||
pos = State.lines[i].data:find(State.search_term)
|
pos = find(State.lines[i].data, State.search_term)
|
||||||
if pos then
|
if pos then
|
||||||
State.cursor1.line = i
|
State.cursor1.line = i
|
||||||
State.cursor1.pos = pos
|
State.cursor1.pos = pos
|
||||||
|
@ -56,12 +49,9 @@ function Text.search_next(State)
|
||||||
end
|
end
|
||||||
if pos == nil then
|
if pos == nil then
|
||||||
-- search current line until cursor
|
-- search current line until cursor
|
||||||
local line = State.lines[State.cursor1.line]
|
pos = find(State.lines[State.cursor1.line].data, State.search_term)
|
||||||
if line.mode == 'text' then
|
if pos and pos < State.cursor1.pos then
|
||||||
pos = line.data:find(State.search_term)
|
State.cursor1.pos = pos
|
||||||
if pos and pos < State.cursor1.pos then
|
|
||||||
State.cursor1.pos = pos
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if pos == nil then
|
if pos == nil then
|
||||||
|
@ -117,7 +107,13 @@ function Text.search_previous(State)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function find(s, pat, i)
|
||||||
|
if s == nil then return end
|
||||||
|
return s:find(pat, i)
|
||||||
|
end
|
||||||
|
|
||||||
function rfind(s, pat, i)
|
function rfind(s, pat, i)
|
||||||
|
if s == nil then return end
|
||||||
local rs = s:reverse()
|
local rs = s:reverse()
|
||||||
local rpat = pat:reverse()
|
local rpat = pat:reverse()
|
||||||
if i == nil then i = #s end
|
if i == nil then i = #s end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user