Skip to content

Commit 362ecbe

Browse files
committed
fix(#2024): revert removal of deprecated nvim-tree.config nvim_tree_callback
1 parent 59bcb01 commit 362ecbe

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

lua/nvim-tree/config.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- INFO: DEPRECATED FILE, DO NOT ADD ANYTHING IN THERE
2+
-- keeping to avoid breaking user configs. Will remove during a weekend.
3+
local M = {}
4+
5+
-- TODO: remove this once the cb property is not supported in mappings, following view.mapping.list removal
6+
function M.nvim_tree_callback(callback_name)
7+
-- generate_on_attach_.* will map this as per mappings.list..action
8+
return callback_name
9+
end
10+
11+
return M

lua/nvim-tree/keymap-legacy.lua

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,26 @@ local function generate_on_attach_function(list, unmapped_keys, remove_defaults)
241241
for _, m in ipairs(M.on_attach.list) do
242242
local keys = type(m.key) == "table" and m.key or { m.key }
243243
for _, k in ipairs(keys) do
244-
if LEGACY_MAPPINGS[m.action] then
245-
-- straight action
244+
local legacy_mapping = LEGACY_MAPPINGS[m.action] or LEGACY_MAPPINGS[m.cb]
245+
if legacy_mapping then
246+
-- straight action or cb, which generated an action string at setup time
246247
vim.keymap.set(
247248
m.mode or "n",
248249
k,
249-
LEGACY_MAPPINGS[m.action].fn,
250-
{ desc = m.action, buffer = bufnr, noremap = true, silent = true, nowait = true }
250+
legacy_mapping.fn,
251+
{ desc = m.cb or m.action, buffer = bufnr, noremap = true, silent = true, nowait = true }
251252
)
252253
elseif type(m.action_cb) == "function" then
253254
-- action_cb
254255
vim.keymap.set(m.mode or "n", k, function()
255256
m.action_cb(api.tree.get_node_under_cursor())
256-
end, { desc = m.action, buffer = bufnr, noremap = true, silent = true, nowait = true })
257+
end, {
258+
desc = m.action or "no description",
259+
buffer = bufnr,
260+
noremap = true,
261+
silent = true,
262+
nowait = true,
263+
})
257264
end
258265
end
259266
end
@@ -285,21 +292,22 @@ local function generate_on_attach_lua(list, unmapped_keys, remove_defaults)
285292
for _, m in ipairs(list) do
286293
local keys = type(m.key) == "table" and m.key or { m.key }
287294
for _, k in ipairs(keys) do
288-
if LEGACY_MAPPINGS[m.action] then
295+
local legacy_mapping = LEGACY_MAPPINGS[m.action] or LEGACY_MAPPINGS[m.cb]
296+
if legacy_mapping then
289297
lua = lua
290298
.. string.format(
291299
[[ vim.keymap.set('%s', '%s', %s, opts('%s'))]],
292300
m.mode or "n",
293301
k,
294-
LEGACY_MAPPINGS[m.action].n,
295-
LEGACY_MAPPINGS[m.action].desc
302+
legacy_mapping.n,
303+
legacy_mapping.desc
296304
)
297305
.. "\n"
298306
elseif type(m.action_cb) == "function" then
299307
lua = lua .. string.format([[ vim.keymap.set('%s', '%s', function()]], m.mode or "n", k) .. "\n"
300308
lua = lua .. [[ local node = api.tree.get_node_under_cursor()]] .. "\n"
301309
lua = lua .. [[ -- your code goes here]] .. "\n"
302-
lua = lua .. string.format([[ end, opts('%s'))]], m.action) .. "\n\n"
310+
lua = lua .. string.format([[ end, opts('%s'))]], m.action or "no description") .. "\n\n"
303311
end
304312
end
305313
end

0 commit comments

Comments
 (0)