Skip to content

Commit

Permalink
feat: single-plugin keys in the lazy view in visual mode (#1476)
Browse files Browse the repository at this point in the history
Applies to all plugins contained in the range
  • Loading branch information
IndianBoy42 committed May 26, 2024
1 parent 8f19915 commit 7667a73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lua/lazy/view/float.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ end
---@param key string
---@param fn fun(self?)
---@param desc? string
function M:on_key(key, fn, desc)
vim.keymap.set("n", key, function()
---@param mode? string[]
function M:on_key(key, fn, desc,mode)
vim.keymap.set(mode or "n", key, function()
fn(self)
end, {
nowait = true,
Expand Down
18 changes: 14 additions & 4 deletions lua/lazy/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,21 @@ function M:setup_modes()
end
if m.key_plugin and name ~= "restore" then
self:on_key(m.key_plugin, function()
local plugin = self.render:get_plugin()
if plugin then
Commands.cmd(name, { plugins = { plugin } })
vim.api.nvim_feedkeys(vim.keycode("<esc>"), "n", false)
local plugins = {}
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
else
plugins[1] = self.render:get_plugin()
end
if #plugins > 0 then
Commands.cmd(name, { plugins = plugins })
end
end, m.desc_plugin)
end, m.desc_plugin, { "n", "x" })
end
end
end
Expand Down

0 comments on commit 7667a73

Please sign in to comment.