Skip to content

Commit 4ce0029

Browse files
committed
fix(grug-far-nvim): improve visual mode mapping
1 parent 2294ae8 commit 4ce0029

File tree

1 file changed

+6
-10
lines changed
  • lua/astrocommunity/search/grug-far-nvim

1 file changed

+6
-10
lines changed

lua/astrocommunity/search/grug-far-nvim/init.lua

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
local default_opts = { instanceName = "main", transient = true }
2-
local function grug_far_open(opts)
2+
local function grug_far_open(opts, with_visual)
33
local grug_far = require "grug-far"
44
opts = require("astrocore").extend_tbl(default_opts, opts)
55
if not grug_far.has_instance(opts.instanceName) then
66
grug_far.open(opts)
77
else
8+
if with_visual then
9+
if not opts.prefills then opts.prefills = {} end
10+
opts.prefills.search = grug_far.get_current_visual_selection()
11+
end
812
grug_far.open_instance(opts.instanceName)
913
if opts.prefills then grug_far.update_instance_prefills(opts.instanceName, opts.prefills, false) end
1014
end
@@ -61,15 +65,7 @@ return {
6165
end,
6266
desc = "Replace current word",
6367
}
64-
maps.x[prefix] = {
65-
function()
66-
local grug_far = require "grug-far"
67-
local grug_opts = require("astrocore").extend_tbl(default_opts, { startCursorRow = 4 })
68-
if grug_far.has_instance(grug_opts.instanceName) then grug_far.close_instance(grug_opts.instanceName) end
69-
grug_far.with_visual_selection(grug_opts)
70-
end,
71-
desc = "Replace selection",
72-
}
68+
maps.x[prefix] = { function() grug_far_open(nil, true) end, desc = "Replace selection" }
7369
end,
7470
},
7571
{

0 commit comments

Comments
 (0)