Skip to content

Commit 589c36e

Browse files
committed
fix(keymap setup): do not crash on vim.fn.extend to explain the user keymap config has changed
1 parent 4a9a17b commit 589c36e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lua/nvim-tree/view.lua

+14-3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ function M._wipe_rogue_buffer()
112112
end
113113
end
114114

115+
local function warn_wrong_mapping()
116+
local warn_str = "Wrong configuration for keymaps, refer to the new documentation. Keymaps setup aborted"
117+
require'nvim-tree.utils'.echo_warning(warn_str)
118+
end
119+
115120
-- set user options and create tree buffer (should never be wiped)
116121
function M.setup()
117122
M.View.side = vim.g.nvim_tree_side or M.View.side
@@ -137,14 +142,20 @@ function M.setup()
137142
if vim.g.nvim_tree_disable_default_keybindings == 1 then
138143
M.View.bindings = user_mappings
139144
else
140-
M.View.bindings = vim.fn.extend(M.View.bindings, user_mappings)
145+
ok, result = pcall(vim.fn.extend, M.View.bindings, user_mappings)
146+
if not ok then
147+
-- TODO: remove this in a few weeks
148+
warn_wrong_mapping()
149+
return
150+
else
151+
M.View.bindings = result
152+
end
141153
end
142154

143155
for _, b in pairs(M.View.bindings) do
144156
-- TODO: remove this in a few weeks
145157
if type(b) == "string" then
146-
local warn_str = "Wrong configuration for keymaps, refer to the new documentation. User keymaps setup aborted"
147-
require'nvim-tree.utils'.echo_warning(warn_str)
158+
warn_wrong_mapping()
148159
break
149160
end
150161
if type(b.key) == "table" then

0 commit comments

Comments
 (0)