Skip to content

Commit d34ea42

Browse files
authored
fix: find file waits for git to finish (#976)
1 parent 1a5ee28 commit d34ea42

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

lua/nvim-tree/actions/find-file.lua

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ local renderer = require"nvim-tree.renderer"
66

77
local M = {}
88

9-
function M.fn(fname)
10-
local i
9+
local function get_index_offset()
1110
local hide_root_folder = view.View.hide_root_folder
12-
if not TreeExplorer then
13-
return
14-
end
1511
if TreeExplorer.cwd == '/' or hide_root_folder then
16-
i = 0
12+
return 0
1713
else
18-
i = 1
14+
return 1
1915
end
16+
end
2017

18+
function M.fn(fname)
19+
if not TreeExplorer then return end
20+
21+
local i = get_index_offset()
2122
local tree_altered = false
2223

2324
local function iterate_nodes(nodes)
@@ -27,26 +28,27 @@ function M.fn(fname)
2728
return i
2829
end
2930

30-
local path_matches = utils.str_find(fname, node.absolute_path..utils.path_separator)
31+
local path_matches = node.nodes and utils.str_find(fname, node.absolute_path..utils.path_separator)
3132
if path_matches then
32-
if #node.nodes == 0 then
33+
if not node.open then
3334
node.open = true
34-
explorer_module.explore(node, node.absolute_path, {})
35+
tree_altered = true
36+
end
37+
38+
if #node.nodes == 0 then
39+
local git_finished = false
3540
git.load_project_status(node.absolute_path, function(status)
36-
if status.dirs or status.files then
37-
require"nvim-tree.actions.reloaders".reload_node_status(node, git.projects)
38-
end
39-
renderer.draw()
41+
explorer_module.explore(node, node.absolute_path, status)
42+
git_finished = true
4043
end)
44+
while not vim.wait(10, function() return git_finished end, 10) do end
4145
end
42-
if node.open == false then
43-
node.open = true
44-
tree_altered = true
45-
end
46+
4647
if iterate_nodes(node.nodes) ~= nil then
4748
return i
4849
end
49-
elseif node.open == true then
50+
-- mandatory to iterate i
51+
elseif node.open then
5052
iterate_nodes(node.nodes)
5153
end
5254
end

0 commit comments

Comments
 (0)