Skip to content

Commit

Permalink
feat(window): more options for mapping keys
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 6, 2024
1 parent 39595e8 commit fdcfc5a
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lua/trouble/view/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -362,23 +362,24 @@ function M:on(events, fn, opts)
end

---@param key string
---@param fn fun(self: trouble.Window)
---@param desc? string
function M:map(key, fn, desc)
---@param fn fun(self: trouble.Window):any
---@param opts? string|vim.keymap.set.Opts
function M:map(key, fn, opts)
opts = vim.tbl_deep_extend("force", {
buffer = self.buf,
nowait = true,
}, type(opts) == "string" and { desc = opts } or opts or {})
---@cast opts vim.keymap.set.Opts
if not self:valid() then
error("Cannot create a keymap for an invalid window")
end
self.keys[key] = desc or key
self.keys[key] = opts.desc or key
local weak_self = Util.weak(self)
vim.keymap.set("n", key, function()
if weak_self() then
fn(weak_self())
return fn(weak_self())
end
end, {
nowait = true,
buffer = self.buf,
desc = desc,
})
end, opts)
end

return M

0 comments on commit fdcfc5a

Please sign in to comment.