Add `find-replace:select-previous`

This commit is contained in:
Guldoman 2021-09-10 21:54:50 +02:00
parent 56eace627a
commit e7be9652c9
No known key found for this signature in database
GPG Key ID: C08A498EC7F1AFDD
2 changed files with 17 additions and 9 deletions

View File

@ -142,7 +142,7 @@ local function is_in_any_selection(line, col)
return false return false
end end
local function select_next(all) local function select_add_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
local text = doc():get_text(l1, c1, l2, c2) local text = doc():get_text(l1, c1, l2, c2)
@ -161,15 +161,22 @@ local function select_next(all)
end end
end end
command.add(has_unique_selection, { local function select_next(reverse)
["find-replace:select-next"] = function() local l1, c1, l2, c2 = doc():get_selection(true)
local l1, c1, l2, c2 = doc():get_selection(true) local text = doc():get_text(l1, c1, l2, c2)
local text = doc():get_text(l1, c1, l2, c2) if reverse then
l1, c1, l2, c2 = search.find(doc(), l1, c1, text, { wrap = true, reverse = true })
else
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 l2 then doc():set_selection(l2, c2, l1, c1) end end
end, if l2 then doc():set_selection(l2, c2, l1, c1) end
["find-replace:select-add-next"] = function() select_next(false) end, end
["find-replace:select-add-all"] = function() select_next(true) end
command.add(has_unique_selection, {
["find-replace:select-next"] = select_next,
["find-replace:select-previous"] = function() select_next(true) end,
["find-replace:select-add-next"] = select_add_next,
["find-replace:select-add-all"] = function() select_add_next(true) end
}) })
command.add("core.docview", { command.add("core.docview", {

View File

@ -170,6 +170,7 @@ keymap.add_direct {
["ctrl+a"] = "doc:select-all", ["ctrl+a"] = "doc:select-all",
["ctrl+d"] = { "find-replace:select-add-next", "doc:select-word" }, ["ctrl+d"] = { "find-replace:select-add-next", "doc:select-word" },
["ctrl+f3"] = "find-replace:select-next", ["ctrl+f3"] = "find-replace:select-next",
["ctrl+shift+f3"] = "find-replace:select-previous",
["ctrl+l"] = "doc:select-lines", ["ctrl+l"] = "doc:select-lines",
["ctrl+shift+l"] = { "find-replace:select-add-all", "doc:select-word" }, ["ctrl+shift+l"] = { "find-replace:select-add-all", "doc:select-word" },
["ctrl+/"] = "doc:toggle-line-comments", ["ctrl+/"] = "doc:toggle-line-comments",