Skip to content

Commit

Permalink
feat(ui): added mapping descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 17, 2024
1 parent 5473e3d commit 6ca90a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lua/lazy/view/float.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function M:mount()
self:augroup(true)
end, { win = true })
self:focus()
self:on_key(ViewConfig.keys.close, self.close)
self:on_key(ViewConfig.keys.close, self.close, "Close")
self:on({ "BufDelete", "BufHidden" }, self.close)

if vim.bo[self.buf].buftype == "" then
Expand Down
26 changes: 14 additions & 12 deletions lua/lazy/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function M.create()
require("lazy.manage.process").abort()
require("lazy.async").abort()
return ViewConfig.keys.abort
end, { silent = true, buffer = self.buf, expr = true })
end, { silent = true, buffer = self.buf, expr = true, desc = "Abort" })

vim.keymap.set("n", "gx", "K", { buffer = self.buf, remap = true })

Expand All @@ -110,7 +110,7 @@ function M.create()
self.state.plugin = open and selected or nil
self:update()
end
end)
end, "Details")

self:on_key(ViewConfig.keys.next, function()
local cursor = vim.api.nvim_win_get_cursor(self.view.win)
Expand All @@ -121,7 +121,7 @@ function M.create()
return
end
end
end)
end, "Next Plugin")

self:on_key(ViewConfig.keys.prev, function()
local cursor = vim.api.nvim_win_get_cursor(self.view.win)
Expand All @@ -132,14 +132,14 @@ function M.create()
return
end
end
end)
end, "Prev Plugin")

self:on_key(ViewConfig.keys.profile_sort, function()
if self.state.mode == "profile" then
self.state.profile.sort_time_taken = not self.state.profile.sort_time_taken
self:update()
end
end)
end, "Sort Profile")

self:on_key(ViewConfig.keys.profile_filter, function()
if self.state.mode == "profile" then
Expand All @@ -159,17 +159,18 @@ function M.create()
end
end)
end
end)
end, "Filter Profile")

for lhs, rhs in pairs(Config.options.ui.custom_keys) do
if rhs then
local handler = type(rhs) == "table" and rhs[1] or rhs
local desc = type(rhs) == "table" and rhs.desc or nil
self:on_key(lhs, function()
local plugin = self.render:get_plugin()
if plugin then
handler(plugin)
end
end)
end, desc)
end
end

Expand Down Expand Up @@ -219,17 +220,17 @@ function M:setup_patterns()
["(https?://%S+)"] = function(url)
Util.open(url)
end,
}, self.hover)
}, self.hover, "Hover")
self:on_pattern(ViewConfig.keys.diff, {
[commit_pattern] = function(hash)
self:diff({ commit = hash })
end,
}, self.diff)
}, self.diff, "Diff")
self:on_pattern(ViewConfig.commands.restore.key_plugin, {
[commit_pattern] = function(hash)
self:restore({ commit = hash })
end,
}, self.restore)
}, self.restore, "Restore")
end

---@param opts? {commit:string}
Expand Down Expand Up @@ -294,7 +295,8 @@ end
---@param key string
---@param patterns table<string, fun(str:string)>
---@param fallback? fun(self)
function M:on_pattern(key, patterns, fallback)
---@param desc? string
function M:on_pattern(key, patterns, fallback, desc)
self:on_key(key, function()
local line = vim.api.nvim_get_current_line()
local pos = vim.api.nvim_win_get_cursor(0)
Expand All @@ -316,7 +318,7 @@ function M:on_pattern(key, patterns, fallback)
if fallback then
fallback(self)
end
end)
end, desc)
end

function M:setup_modes()
Expand Down

0 comments on commit 6ca90a2

Please sign in to comment.