From cd7be73b080e94a75d0269d70eabb0a19f8741b6 Mon Sep 17 00:00:00 2001 From: kiyan Date: Sat, 2 Oct 2021 14:20:20 +0200 Subject: [PATCH] feat: completely filter out base mappings if user mappings are defined --- lua/nvim-tree/view.lua | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index dbef4189..3be8d076 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -114,6 +114,29 @@ local DEFAULT_CONFIG = { } } +local function merge_mappings(user_mappings) + if #user_mappings == 0 then + return M.View.mappings + end + + local user_keys = {} + for _, map in pairs(user_mappings) do + if type(map.key) == "table" then + for _, key in pairs(map.key) do + table.insert(user_keys, key) + end + else + table.insert(user_keys, map.key) + end + end + + local view_mappings = vim.tbl_filter(function(map) + return not vim.tbl_contains(user_keys, map.key) + end, M.View.mappings) + + return vim.fn.extend(view_mappings, user_mappings) +end + function M.setup(opts) local options = vim.tbl_deep_extend('force', DEFAULT_CONFIG, opts) M.View.side = options.side @@ -122,7 +145,7 @@ function M.setup(opts) if options.mappings.custom_only then M.View.mappings = options.mappings.list else - M.View.mappings = vim.fn.extend(M.View.mappings, options.mappings.list) + M.View.mappings = merge_mappings(options.mappings.list) end vim.cmd "augroup NvimTreeView"