fix(actions): help, close and custom only

fixes #908
This commit is contained in:
kiyan
2022-01-21 15:56:07 +01:00
parent 00807d7bd5
commit b5c2e52ed0
2 changed files with 8 additions and 7 deletions

View File

@@ -77,7 +77,7 @@ local keypress_funcs = {
prev_git_item = go_to('prev_git_item'), prev_git_item = go_to('prev_git_item'),
next_git_item = go_to('next_git_item'), next_git_item = go_to('next_git_item'),
dir_up = lib.dir_up, dir_up = lib.dir_up,
close = function() M.close() end, close = function() require'nvim-tree'.close() end,
preview = function(node) preview = function(node)
if node.name == '..' then if node.name == '..' then
return return
@@ -173,7 +173,7 @@ function M.setup(opts)
local user_map_config = (opts.view or {}).mappings or {} local user_map_config = (opts.view or {}).mappings or {}
local options = vim.tbl_deep_extend('force', DEFAULT_MAPPING_CONFIG, user_map_config) local options = vim.tbl_deep_extend('force', DEFAULT_MAPPING_CONFIG, user_map_config)
if options.custom_only then if options.custom_only then
M.mappings = options.mappings.list M.mappings = options.list
else else
M.mappings = merge_mappings(options.list) M.mappings = merge_mappings(options.list)
end end

View File

@@ -5,22 +5,23 @@ function M.compute_lines()
local help_lines = {'HELP'} local help_lines = {'HELP'}
local help_hl = {{'NvimTreeRootFolder', 0, 0, #help_lines[1]}} local help_hl = {{'NvimTreeRootFolder', 0, 0, #help_lines[1]}}
local mappings = vim.tbl_filter(function(v) local mappings = vim.tbl_filter(function(v)
return v.cb ~= nil and v.cb ~= "" return (v.cb ~= nil and v.cb ~= "") or (v.action ~= nil and v.action ~= "")
end, view.View.mappings) end, require'nvim-tree.actions'.mappings)
local processed = {} local processed = {}
for _, b in pairs(mappings) do for _, b in pairs(mappings) do
local cb = b.cb local cb = b.cb
local key = b.key local key = b.key
local name local name
if cb:sub(1,35) == view.nvim_tree_callback('test'):sub(1,35) then if cb and cb:sub(1,35) == require'nvim-tree.config'.nvim_tree_callback('test'):sub(1,35) then
name = cb:match("'[^']+'[^']*$") name = cb:match("'[^']+'[^']*$")
name = name:match("'[^']+'") name = name:match("'[^']+'")
table.insert(processed, {key, name, true}) elseif b.action then
name = b.action
else else
name = (b.name ~= nil) and b.name or cb name = (b.name ~= nil) and b.name or cb
name = '"' .. name .. '"' name = '"' .. name .. '"'
table.insert(processed, {key, name, false})
end end
table.insert(processed, {key, name, true})
end end
table.sort(processed, function(a,b) table.sort(processed, function(a,b)
return (a[3] == b[3] return (a[3] == b[3]