Skip to content

Commit 0a123d4

Browse files
committed
fix(#1815): don't schedule find file calls
1 parent 7177d95 commit 0a123d4

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

lua/nvim-tree.lua

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function M.toggle(find_file, no_focus, cwd, bang)
7676
local previous_buf = vim.api.nvim_get_current_buf()
7777
M.open(cwd)
7878
if _config.update_focused_file.enable or find_file then
79-
M.find_file(false, previous_buf, bang)
79+
find_file(false, previous_buf, bang)
8080
end
8181
if no_focus then
8282
vim.cmd "noautocmd wincmd p"
@@ -143,7 +143,7 @@ local function is_file_readable(fname)
143143
return stat and stat.type == "file" and vim.loop.fs_access(fname, "R")
144144
end
145145

146-
function M.find_file(with_open, bufnr, bang)
146+
local function find_file(with_open, bufnr, bang)
147147
if not with_open and not core.get_explorer() then
148148
return
149149
end
@@ -162,13 +162,11 @@ function M.find_file(with_open, bufnr, bang)
162162
M.open()
163163
end
164164

165-
-- if we don't schedule, it will search for NvimTree
166-
vim.schedule(function()
167-
if bang or _config.update_focused_file.update_root then
168-
M.change_root(filepath, bufnr)
169-
end
170-
require("nvim-tree.actions.finders.find-file").fn(filepath)
171-
end)
165+
if bang or _config.update_focused_file.update_root then
166+
M.change_root(filepath, bufnr)
167+
end
168+
169+
require("nvim-tree.actions.finders.find-file").fn(filepath)
172170
end
173171

174172
M.resize = view.resize
@@ -272,7 +270,7 @@ function M.on_enter(netrw_disabled)
272270
if should_focus_other_window then
273271
vim.cmd "noautocmd wincmd p"
274272
if should_find then
275-
M.find_file(false)
273+
find_file(false)
276274
end
277275
end
278276
end
@@ -306,7 +304,7 @@ local function setup_vim_commands()
306304
vim.api.nvim_create_user_command("NvimTreeRefresh", reloaders.reload_explorer, { bar = true })
307305
vim.api.nvim_create_user_command("NvimTreeClipboard", copy_paste.print_clipboard, { bar = true })
308306
vim.api.nvim_create_user_command("NvimTreeFindFile", function(res)
309-
M.find_file(true, nil, res.bang)
307+
find_file(true, nil, res.bang)
310308
end, { bang = true, bar = true })
311309
vim.api.nvim_create_user_command("NvimTreeFindFileToggle", function(res)
312310
M.toggle(true, false, res.args, res.bang)
@@ -324,7 +322,7 @@ function M.change_dir(name)
324322
change_dir.fn(name)
325323

326324
if _config.update_focused_file.enable then
327-
M.find_file(false)
325+
find_file(false)
328326
end
329327
end
330328

@@ -400,7 +398,7 @@ local function setup_autocommands(opts)
400398
if opts.update_focused_file.enable then
401399
create_nvim_tree_autocmd("BufEnter", {
402400
callback = function()
403-
M.find_file(false)
401+
find_file(false)
404402
end,
405403
})
406404
end

0 commit comments

Comments
 (0)