From fdcfc5a200491e9509e56e04c6b3cdee8ada3153 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 6 Jun 2024 20:03:53 +0200 Subject: [PATCH] feat(window): more options for mapping keys --- lua/trouble/view/window.lua | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lua/trouble/view/window.lua b/lua/trouble/view/window.lua index 9d25112c..546b1fb0 100644 --- a/lua/trouble/view/window.lua +++ b/lua/trouble/view/window.lua @@ -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