feat: single-plugin keys in the lazy view in visual mode (#1476)

Applies to all plugins contained in the range
This commit is contained in:
Anshuman Medhi 2024-05-26 16:40:08 +08:00 committed by GitHub
parent 8f19915175
commit 7667a73dee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 6 deletions

View File

@ -251,8 +251,9 @@ end
---@param key string ---@param key string
---@param fn fun(self?) ---@param fn fun(self?)
---@param desc? string ---@param desc? string
function M:on_key(key, fn, desc) ---@param mode? string[]
vim.keymap.set("n", key, function() function M:on_key(key, fn, desc,mode)
vim.keymap.set(mode or "n", key, function()
fn(self) fn(self)
end, { end, {
nowait = true, nowait = true,

View File

@ -297,11 +297,21 @@ function M:setup_modes()
end end
if m.key_plugin and name ~= "restore" then if m.key_plugin and name ~= "restore" then
self:on_key(m.key_plugin, function() self:on_key(m.key_plugin, function()
local plugin = self.render:get_plugin() vim.api.nvim_feedkeys(vim.keycode("<esc>"), "n", false)
if plugin then local plugins = {}
Commands.cmd(name, { plugins = { plugin } }) if vim.api.nvim_get_mode().mode:lower() == "v" then
local f, t = vim.fn.line("."), vim.fn.line("v")
if f > t then f, t = t, f end
for i = f, t do
plugins[#plugins + 1] = self.render:get_plugin(i)
end end
end, m.desc_plugin) else
plugins[1] = self.render:get_plugin()
end
if #plugins > 0 then
Commands.cmd(name, { plugins = plugins })
end
end, m.desc_plugin, { "n", "x" })
end end
end end
end end