Allow `find-replace:select-next` to select more occurrences after wrap
The initial position for the search is defined by the last selection towards the end of the file. After reaching the end of the file, it would always select the same selection to start the search from. Now, we start the search from each selection, until a new occurrence is found.
This commit is contained in:
parent
7a24dbb17e
commit
17185075c6
|
@ -108,6 +108,20 @@ local function has_unique_selection()
|
||||||
return text ~= nil
|
return text ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function is_in_selection(line, col, l1, c1, l2, c2)
|
||||||
|
if line < l1 or line > l2 then return false end
|
||||||
|
if line == l1 and col <= c1 then return false end
|
||||||
|
if line == l2 and col > c2 then return false end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function is_in_any_selection(line, col)
|
||||||
|
for idx, l1, c1, l2, c2 in doc():get_selections(true, false) do
|
||||||
|
if is_in_selection(line, col, l1, c1, l2, c2) then return true end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local function select_next(all)
|
local function select_next(all)
|
||||||
local il1, ic1 = doc():get_selection(true)
|
local il1, ic1 = doc():get_selection(true)
|
||||||
for idx, l1, c1, l2, c2 in doc():get_selections(true, true) do
|
for idx, l1, c1, l2, c2 in doc():get_selections(true, true) do
|
||||||
|
@ -115,9 +129,15 @@ local function select_next(all)
|
||||||
repeat
|
repeat
|
||||||
l1, c1, l2, c2 = search.find(doc(), l2, c2, text, { wrap = true })
|
l1, c1, l2, c2 = search.find(doc(), l2, c2, text, { wrap = true })
|
||||||
if l1 == il1 and c1 == ic1 then break end
|
if l1 == il1 and c1 == ic1 then break end
|
||||||
if l2 then doc():add_selection(l2, c2, l1, c1) end
|
if l2 and (all or not is_in_any_selection(l2, c2)) then
|
||||||
|
doc():add_selection(l2, c2, l1, c1)
|
||||||
|
if not all then
|
||||||
|
core.active_view:scroll_to_make_visible(l2, c2)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
until not all or not l2
|
until not all or not l2
|
||||||
break
|
if all then break end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue