@@ -3,7 +3,6 @@ local a = vim.api
3
3
local log = require " nvim-tree.log"
4
4
local view = require " nvim-tree.view"
5
5
local util = require " nvim-tree.utils"
6
- local nvim_tree_callback = require (" nvim-tree.config" ).nvim_tree_callback
7
6
8
7
-- BEGIN_DEFAULT_MAPPINGS
9
8
local DEFAULT_MAPPINGS = {
@@ -240,15 +239,32 @@ local M = {
240
239
custom_keypress_funcs = {},
241
240
}
242
241
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
+
243
257
function M .apply_mappings (bufnr )
258
+ local setter_for = set_map_for (bufnr )
244
259
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 )
249
267
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 })
252
268
end
253
269
end
254
270
end
@@ -330,13 +346,11 @@ local function cleanup_existing_mappings()
330
346
if bufnr == nil or not a .nvim_buf_is_valid (bufnr ) then
331
347
return
332
348
end
349
+
333
350
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 })
340
354
end
341
355
end
342
356
end
0 commit comments