Skip to content

Commit 986c79a

Browse files
committed
fix: correctly pass explorer as first arg when calling explorer methods in lua/nvim-tree
1 parent 4995699 commit 986c79a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lua/nvim-tree.lua

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ local M = {
1313

1414
--- Helper function to execute some explorer method safely
1515
---@param fn string # key of explorer
16+
---@param ... any|nil
1617
---@return function|nil
17-
local function explorer_fn(fn)
18+
local function explorer_fn(fn, ...)
1819
local explorer = core.get_explorer()
1920
if explorer then
20-
return explorer[fn]
21+
return explorer[fn](explorer, ...)
2122
end
2223
end
2324

@@ -57,7 +58,7 @@ function M.change_root(path, bufnr)
5758
-- test if in vim_cwd
5859
if utils.path_relative(path, vim_cwd) ~= path then
5960
if vim_cwd ~= cwd then
60-
explorer_fn("change_dir")(vim_cwd)
61+
explorer_fn("change_dir", vim_cwd)
6162
end
6263
return
6364
end
@@ -68,19 +69,19 @@ function M.change_root(path, bufnr)
6869

6970
-- otherwise test M.init_root
7071
if _config.prefer_startup_root and utils.path_relative(path, M.init_root) ~= path then
71-
explorer_fn("change_dir")(M.init_root)
72+
explorer_fn("change_dir", M.init_root)
7273
return
7374
end
7475
-- otherwise root_dirs
7576
for _, dir in pairs(_config.root_dirs) do
7677
dir = vim.fn.fnamemodify(dir, ":p")
7778
if utils.path_relative(path, dir) ~= path then
78-
explorer_fn("change_dir")(dir)
79+
explorer_fn("change_dir", dir)
7980
return
8081
end
8182
end
8283
-- finally fall back to the folder containing the file
83-
explorer_fn("change_dir")(vim.fn.fnamemodify(path, ":p:h"))
84+
explorer_fn("change_dir", vim.fn.fnamemodify, path, ":p:h")
8485
end
8586

8687
function M.tab_enter()
@@ -120,7 +121,7 @@ function M.open_on_directory()
120121
return
121122
end
122123

123-
explorer_fn("force_dirchange")(bufname, true)
124+
explorer_fn("force_dirchange", bufname, true)
124125
end
125126

126127
---@return table
@@ -144,7 +145,7 @@ end
144145
---@param name string|nil
145146
function M.change_dir(name)
146147
if name then
147-
explorer_fn("change_dir")(name)
148+
explorer_fn("change_dir", name)
148149
end
149150

150151
if _config.update_focused_file.update_root.enable then

0 commit comments

Comments
 (0)