mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
feat(float): better key mappings
This commit is contained in:
parent
66b252535c
commit
a171a815b3
1 changed files with 25 additions and 6 deletions
|
|
@ -12,6 +12,11 @@ local M = setmetatable({}, {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
---@class snacks.float.Keys: vim.api.keyset.keymap
|
||||||
|
---@field [1]? string
|
||||||
|
---@field [2]? string|fun(self: snacks.float): any
|
||||||
|
---@field mode? string|string[]
|
||||||
|
|
||||||
---@class snacks.float.Config
|
---@class snacks.float.Config
|
||||||
---@field buf? number
|
---@field buf? number
|
||||||
---@field file? string
|
---@field file? string
|
||||||
|
|
@ -135,12 +140,26 @@ function M:show()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
for key, fn in pairs(self.opts.keys) do
|
for key, spec in pairs(self.opts.keys) do
|
||||||
if fn then
|
if spec then
|
||||||
fn = type(fn) == "string" and self[fn] or fn
|
if type(spec) == "string" then
|
||||||
vim.keymap.set("n", key, function()
|
spec = { key, self[spec] and self[spec] or spec, desc = spec }
|
||||||
fn(self)
|
elseif type(spec) == "function" then
|
||||||
end, { buffer = self.buf })
|
spec = { key, spec }
|
||||||
|
end
|
||||||
|
local opts = vim.deepcopy(spec)
|
||||||
|
opts[1] = nil
|
||||||
|
opts[2] = nil
|
||||||
|
opts.mode = nil
|
||||||
|
opts.buffer = self.buf
|
||||||
|
local rhs = spec[2]
|
||||||
|
if type(rhs) == "function" then
|
||||||
|
rhs = function()
|
||||||
|
return spec[2](self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
---@cast spec snacks.float.Keys
|
||||||
|
vim.keymap.set(spec.mode or "n", spec[1], rhs, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue