From 43c284a57870e1a7ed42782eacf444a6a752f81e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maria=20Jos=C3=A9=20Solano?= Date: Wed, 11 Oct 2023 22:18:53 -0700 Subject: [PATCH] feat(keys): include custom keys in help menu (#1105) --- README.md | 33 +++++++++++++++++++-------------- doc/lazy.nvim.txt | 37 +++++++++++++++++++++---------------- lua/lazy/core/config.lua | 33 +++++++++++++++++++-------------- lua/lazy/view/init.lua | 7 ++++--- lua/lazy/view/render.lua | 8 ++++++++ 5 files changed, 71 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index f17dd46..13b25e1 100644 --- a/README.md +++ b/README.md @@ -371,22 +371,27 @@ return { browser = nil, ---@type string? throttle = 20, -- how frequently should the ui process render events custom_keys = { - -- you can define custom key maps here. - -- To disable one of the defaults, set it to false + -- You can define custom key maps here. If present, the description will + -- be shown in the help menu. + -- To disable one of the defaults, set it to false. - -- open lazygit log - ["l"] = function(plugin) - require("lazy.util").float_term({ "lazygit", "log" }, { - cwd = plugin.dir, - }) - end, + ["l"] = { + function(plugin) + require("lazy.util").float_term({ "lazygit", "log" }, { + cwd = plugin.dir, + }) + end, + desc = "Open lazygit log", + }, - -- open a terminal for the plugin dir - ["t"] = function(plugin) - require("lazy.util").float_term(nil, { - cwd = plugin.dir, - }) - end, + ["t"] = { + function(plugin) + require("lazy.util").float_term(nil, { + cwd = plugin.dir, + }) + end, + desc = "Open terminal in plugin dir", + }, }, }, diff = { diff --git a/doc/lazy.nvim.txt b/doc/lazy.nvim.txt index 62a6025..a0cd52f 100644 --- a/doc/lazy.nvim.txt +++ b/doc/lazy.nvim.txt @@ -473,22 +473,27 @@ CONFIGURATION *lazy.nvim-lazy.nvim-configuration* browser = nil, ---@type string? throttle = 20, -- how frequently should the ui process render events custom_keys = { - -- you can define custom key maps here. - -- To disable one of the defaults, set it to false - - -- open lazygit log - ["l"] = function(plugin) - require("lazy.util").float_term({ "lazygit", "log" }, { - cwd = plugin.dir, - }) - end, - - -- open a terminal for the plugin dir - ["t"] = function(plugin) - require("lazy.util").float_term(nil, { - cwd = plugin.dir, - }) - end, + -- You can define custom key maps here. If present, the description will + -- be shown in the help menu. + -- To disable one of the defaults, set it to false. + + ["l"] = { + function(plugin) + require("lazy.util").float_term({ "lazygit", "log" }, { + cwd = plugin.dir, + }) + end, + desc = "Open lazygit log", + }, + + ["t"] = { + function(plugin) + require("lazy.util").float_term(nil, { + cwd = plugin.dir, + }) + end, + desc = "Open terminal in plugin dir", + }, }, }, diff = { diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index e74eee6..81b4477 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -81,22 +81,27 @@ M.defaults = { browser = nil, ---@type string? throttle = 20, -- how frequently should the ui process render events custom_keys = { - -- you can define custom key maps here. - -- To disable one of the defaults, set it to false + -- You can define custom key maps here. If present, the description will + -- be shown in the help menu. + -- To disable one of the defaults, set it to false. - -- open lazygit log - ["l"] = function(plugin) - require("lazy.util").float_term({ "lazygit", "log" }, { - cwd = plugin.dir, - }) - end, + ["l"] = { + function(plugin) + require("lazy.util").float_term({ "lazygit", "log" }, { + cwd = plugin.dir, + }) + end, + desc = "Open lazygit log", + }, - -- open a terminal for the plugin dir - ["t"] = function(plugin) - require("lazy.util").float_term(nil, { - cwd = plugin.dir, - }) - end, + ["t"] = { + function(plugin) + require("lazy.util").float_term(nil, { + cwd = plugin.dir, + }) + end, + desc = "Open terminal in plugin dir", + }, }, }, diff = { diff --git a/lua/lazy/view/init.lua b/lua/lazy/view/init.lua index 1be4b16..e62fc6e 100644 --- a/lua/lazy/view/init.lua +++ b/lua/lazy/view/init.lua @@ -121,9 +121,10 @@ function M.create() end end) - for key, handler in pairs(Config.options.ui.custom_keys) do - if handler then - self:on_key(key, function() + for lhs, rhs in pairs(Config.options.ui.custom_keys) do + if rhs then + local handler = type(rhs) == "table" and rhs[1] or rhs + self:on_key(lhs, function() local plugin = self.render:get_plugin() if plugin then handler(plugin) diff --git a/lua/lazy/view/render.lua b/lua/lazy/view/render.lua index d4cfdfb..fca229b 100644 --- a/lua/lazy/view/render.lua +++ b/lua/lazy/view/render.lua @@ -209,6 +209,14 @@ function M:help() self:append(" " .. (mode.desc_plugin or mode.desc)):nl() end end + for lhs, rhs in pairs(Config.options.ui.custom_keys) do + if type(rhs) == "table" and rhs.desc then + self:append("- ", "LazySpecial", { indent = 2 }) + self:append("Custom key ", "Title") + self:append(lhs, "LazyProp") + self:append(" " .. rhs.desc):nl() + end + end end function M:progressbar()