feat(ui): added mapping descriptions

This commit is contained in:
Folke Lemaitre 2024-07-18 00:40:41 +02:00
parent 5473e3d77c
commit 6ca90a2120
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 15 additions and 13 deletions

View File

@ -166,7 +166,7 @@ function M:mount()
self:augroup(true) self:augroup(true)
end, { win = true }) end, { win = true })
self:focus() 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) self:on({ "BufDelete", "BufHidden" }, self.close)
if vim.bo[self.buf].buftype == "" then if vim.bo[self.buf].buftype == "" then

View File

@ -85,7 +85,7 @@ function M.create()
require("lazy.manage.process").abort() require("lazy.manage.process").abort()
require("lazy.async").abort() require("lazy.async").abort()
return ViewConfig.keys.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 }) vim.keymap.set("n", "gx", "K", { buffer = self.buf, remap = true })
@ -110,7 +110,7 @@ function M.create()
self.state.plugin = open and selected or nil self.state.plugin = open and selected or nil
self:update() self:update()
end end
end) end, "Details")
self:on_key(ViewConfig.keys.next, function() self:on_key(ViewConfig.keys.next, function()
local cursor = vim.api.nvim_win_get_cursor(self.view.win) local cursor = vim.api.nvim_win_get_cursor(self.view.win)
@ -121,7 +121,7 @@ function M.create()
return return
end end
end end
end) end, "Next Plugin")
self:on_key(ViewConfig.keys.prev, function() self:on_key(ViewConfig.keys.prev, function()
local cursor = vim.api.nvim_win_get_cursor(self.view.win) local cursor = vim.api.nvim_win_get_cursor(self.view.win)
@ -132,14 +132,14 @@ function M.create()
return return
end end
end end
end) end, "Prev Plugin")
self:on_key(ViewConfig.keys.profile_sort, function() self:on_key(ViewConfig.keys.profile_sort, function()
if self.state.mode == "profile" then if self.state.mode == "profile" then
self.state.profile.sort_time_taken = not self.state.profile.sort_time_taken self.state.profile.sort_time_taken = not self.state.profile.sort_time_taken
self:update() self:update()
end end
end) end, "Sort Profile")
self:on_key(ViewConfig.keys.profile_filter, function() self:on_key(ViewConfig.keys.profile_filter, function()
if self.state.mode == "profile" then if self.state.mode == "profile" then
@ -159,17 +159,18 @@ function M.create()
end end
end) end)
end end
end) end, "Filter Profile")
for lhs, rhs in pairs(Config.options.ui.custom_keys) do for lhs, rhs in pairs(Config.options.ui.custom_keys) do
if rhs then if rhs then
local handler = type(rhs) == "table" and rhs[1] or rhs 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() self:on_key(lhs, function()
local plugin = self.render:get_plugin() local plugin = self.render:get_plugin()
if plugin then if plugin then
handler(plugin) handler(plugin)
end end
end) end, desc)
end end
end end
@ -219,17 +220,17 @@ function M:setup_patterns()
["(https?://%S+)"] = function(url) ["(https?://%S+)"] = function(url)
Util.open(url) Util.open(url)
end, end,
}, self.hover) }, self.hover, "Hover")
self:on_pattern(ViewConfig.keys.diff, { self:on_pattern(ViewConfig.keys.diff, {
[commit_pattern] = function(hash) [commit_pattern] = function(hash)
self:diff({ commit = hash }) self:diff({ commit = hash })
end, end,
}, self.diff) }, self.diff, "Diff")
self:on_pattern(ViewConfig.commands.restore.key_plugin, { self:on_pattern(ViewConfig.commands.restore.key_plugin, {
[commit_pattern] = function(hash) [commit_pattern] = function(hash)
self:restore({ commit = hash }) self:restore({ commit = hash })
end, end,
}, self.restore) }, self.restore, "Restore")
end end
---@param opts? {commit:string} ---@param opts? {commit:string}
@ -294,7 +295,8 @@ end
---@param key string ---@param key string
---@param patterns table<string, fun(str:string)> ---@param patterns table<string, fun(str:string)>
---@param fallback? fun(self) ---@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() self:on_key(key, function()
local line = vim.api.nvim_get_current_line() local line = vim.api.nvim_get_current_line()
local pos = vim.api.nvim_win_get_cursor(0) local pos = vim.api.nvim_win_get_cursor(0)
@ -316,7 +318,7 @@ function M:on_pattern(key, patterns, fallback)
if fallback then if fallback then
fallback(self) fallback(self)
end end
end) end, desc)
end end
function M:setup_modes() function M:setup_modes()