Added resetting of selection on intermediate find-text failure

This commit is contained in:
rxi 2020-06-04 13:57:27 +01:00
parent 3569abcb53
commit bd0644a5bb

View file

@ -45,23 +45,24 @@ local function find(label, search_fn)
else else
core.error("Couldn't find %q", text) core.error("Couldn't find %q", text)
dv.doc:set_selection(table.unpack(sel)) dv.doc:set_selection(table.unpack(sel))
dv:scroll_to_make_visible(sel[1], sel[2])
end end
end, function(text) end, function(text)
local ok, line1, col1, line2, col2 = pcall(search_fn, dv.doc, sel[1], sel[2], text) local ok, line1, col1, line2, col2 = pcall(search_fn, dv.doc, sel[1], sel[2], text)
if text == "" then if ok and line1 and text ~= "" then
dv.doc:set_selection(table.unpack(sel))
elseif ok and line1 then
dv.doc:set_selection(line2, col2, line1, col1) dv.doc:set_selection(line2, col2, line1, col1)
dv:scroll_to_line(line2, true) dv:scroll_to_line(line2, true)
found = true found = true
else else
dv.doc:set_selection(table.unpack(sel))
found = false found = false
end end
end, function(explicit) end, function(explicit)
if explicit then if explicit then
dv.doc:set_selection(table.unpack(sel)) dv.doc:set_selection(table.unpack(sel))
dv:scroll_to_make_visible(sel[1], sel[2])
end end
end) end)
end end