@@ -3,7 +3,6 @@ local a = vim.api
33local log = require " nvim-tree.log"
44local view = require " nvim-tree.view"
55local util = require " nvim-tree.utils"
6- local nvim_tree_callback = require (" nvim-tree.config" ).nvim_tree_callback
76
87-- BEGIN_DEFAULT_MAPPINGS
98local DEFAULT_MAPPINGS = {
@@ -240,15 +239,32 @@ local M = {
240239 custom_keypress_funcs = {},
241240}
242241
242+ local function set_map_for (bufnr )
243+ local opts = { noremap = true , silent = true , nowait = true , buffer = bufnr }
244+ return function (mode , rhs )
245+ return function (lhs )
246+ vim .keymap .set (mode or " n" , lhs , rhs , opts )
247+ end
248+ end
249+ end
250+
251+ local function run_dispatch (action )
252+ return function ()
253+ require (" nvim-tree.actions.dispatch" ).dispatch (action )
254+ end
255+ end
256+
243257function M .apply_mappings (bufnr )
258+ local setter_for = set_map_for (bufnr )
244259 for _ , b in pairs (M .mappings ) do
245- local mapping_rhs = b .cb or nvim_tree_callback (b .action )
246- if type (b .key ) == " table" then
247- for _ , key in pairs (b .key ) do
248- a .nvim_buf_set_keymap (bufnr , b .mode or " n" , key , mapping_rhs , { noremap = true , silent = true , nowait = true })
260+ local rhs = b .cb or run_dispatch (b .action )
261+ if rhs then
262+ local setter = setter_for (b .mode , rhs )
263+
264+ local keys = type (b .key ) == " table" and b .key or { b .key }
265+ for _ , key in pairs (keys ) do
266+ setter (key )
249267 end
250- elseif mapping_rhs then
251- a .nvim_buf_set_keymap (bufnr , b .mode or " n" , b .key , mapping_rhs , { noremap = true , silent = true , nowait = true })
252268 end
253269 end
254270end
@@ -330,13 +346,11 @@ local function cleanup_existing_mappings()
330346 if bufnr == nil or not a .nvim_buf_is_valid (bufnr ) then
331347 return
332348 end
349+
333350 for _ , b in pairs (M .mappings ) do
334- if type (b .key ) == " table" then
335- for _ , key in pairs (b .key ) do
336- a .nvim_buf_del_keymap (bufnr , b .mode or " n" , key )
337- end
338- else
339- a .nvim_buf_del_keymap (bufnr , b .mode or " n" , b .key )
351+ local keys = type (b .key ) == " table" and b .key or { b .key }
352+ for _ , key in pairs (keys ) do
353+ vim .keymap .del (b .mode or " n" , key , { buffer = bufnr })
340354 end
341355 end
342356end
0 commit comments