From e6378d4c9b3c238df814526d65a05524f1f8010b Mon Sep 17 00:00:00 2001 From: Luke Kershaw <35707277+l-kershaw@users.noreply.github.com> Date: Fri, 2 Jul 2021 22:24:42 +0100 Subject: [PATCH 1/2] feat(help ui): allow custom names to be provided for custom keybinds - allows users to pass a `name` key when defining a custom binding - defaults to the `cb` string when `name` is not present - `name` key is ignored for built in callbacks --- lua/nvim-tree/renderer.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lua/nvim-tree/renderer.lua b/lua/nvim-tree/renderer.lua index 56268051ce4..c23a77caa54 100644 --- a/lua/nvim-tree/renderer.lua +++ b/lua/nvim-tree/renderer.lua @@ -376,13 +376,15 @@ function M.draw_help() for _, b in pairs(bindings) do local cb = b.cb local key = b.key + local name if cb:sub(1,35) == view.nvim_tree_callback('test'):sub(1,35) then - cb = cb:match("'[^']+'[^']*$") - cb = cb:match("'[^']+'") - table.insert(processed, {key, cb, true}) + name = cb:match("'[^']+'[^']*$") + name = name:match("'[^']+'") + table.insert(processed, {key, name, true}) else - cb = '"' .. cb .. '"' - table.insert(processed, {key, cb, false}) + name = (b.name ~= nil) and b.name or cb + name = '"' .. name .. '"' + table.insert(processed, {key, name, false}) end end table.sort(processed, function(a,b) From 8e52300a549b0b4315ba2a93fedc967042f8544c Mon Sep 17 00:00:00 2001 From: Luke Kershaw <35707277+l-kershaw@users.noreply.github.com> Date: Fri, 2 Jul 2021 23:10:43 +0100 Subject: [PATCH 2/2] lint --- lua/nvim-tree/view.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 1e5fb3d2bca..6309ee15598 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -142,7 +142,7 @@ function M.setup() if vim.g.nvim_tree_disable_default_keybindings == 1 then M.View.bindings = user_mappings else - ok, result = pcall(vim.fn.extend, M.View.bindings, user_mappings) + local ok, result = pcall(vim.fn.extend, M.View.bindings, user_mappings) if not ok then -- TODO: remove this in a few weeks warn_wrong_mapping()