Skip to content

Commit cd7be73

Browse files
committed
feat: completely filter out base mappings if user mappings are defined
1 parent 6416ea3 commit cd7be73

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

lua/nvim-tree/view.lua

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,29 @@ local DEFAULT_CONFIG = {
114114
}
115115
}
116116

117+
local function merge_mappings(user_mappings)
118+
if #user_mappings == 0 then
119+
return M.View.mappings
120+
end
121+
122+
local user_keys = {}
123+
for _, map in pairs(user_mappings) do
124+
if type(map.key) == "table" then
125+
for _, key in pairs(map.key) do
126+
table.insert(user_keys, key)
127+
end
128+
else
129+
table.insert(user_keys, map.key)
130+
end
131+
end
132+
133+
local view_mappings = vim.tbl_filter(function(map)
134+
return not vim.tbl_contains(user_keys, map.key)
135+
end, M.View.mappings)
136+
137+
return vim.fn.extend(view_mappings, user_mappings)
138+
end
139+
117140
function M.setup(opts)
118141
local options = vim.tbl_deep_extend('force', DEFAULT_CONFIG, opts)
119142
M.View.side = options.side
@@ -122,7 +145,7 @@ function M.setup(opts)
122145
if options.mappings.custom_only then
123146
M.View.mappings = options.mappings.list
124147
else
125-
M.View.mappings = vim.fn.extend(M.View.mappings, options.mappings.list)
148+
M.View.mappings = merge_mappings(options.mappings.list)
126149
end
127150

128151
vim.cmd "augroup NvimTreeView"

0 commit comments

Comments
 (0)