fix(keymap setup): do not crash on vim.fn.extend to explain the user keymap config has changed

This commit is contained in:
kiyan
2021-07-02 15:12:12 +02:00
parent 4a9a17b7f1
commit 589c36e26f

View File

@@ -112,6 +112,11 @@ function M._wipe_rogue_buffer()
end
end
local function warn_wrong_mapping()
local warn_str = "Wrong configuration for keymaps, refer to the new documentation. Keymaps setup aborted"
require'nvim-tree.utils'.echo_warning(warn_str)
end
-- set user options and create tree buffer (should never be wiped)
function M.setup()
M.View.side = vim.g.nvim_tree_side or M.View.side
@@ -137,14 +142,20 @@ function M.setup()
if vim.g.nvim_tree_disable_default_keybindings == 1 then
M.View.bindings = user_mappings
else
M.View.bindings = vim.fn.extend(M.View.bindings, user_mappings)
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()
return
else
M.View.bindings = result
end
end
for _, b in pairs(M.View.bindings) do
-- TODO: remove this in a few weeks
if type(b) == "string" then
local warn_str = "Wrong configuration for keymaps, refer to the new documentation. User keymaps setup aborted"
require'nvim-tree.utils'.echo_warning(warn_str)
warn_wrong_mapping()
break
end
if type(b.key) == "table" then