From d34ea422548503fb51d5ce4435e47b2534b13493 Mon Sep 17 00:00:00 2001 From: Kiyan Date: Tue, 15 Feb 2022 08:22:56 +0100 Subject: [PATCH] fix: find file waits for git to finish (#976) --- lua/nvim-tree/actions/find-file.lua | 42 +++++++++++++++-------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/lua/nvim-tree/actions/find-file.lua b/lua/nvim-tree/actions/find-file.lua index 3b444119..b47edb5e 100644 --- a/lua/nvim-tree/actions/find-file.lua +++ b/lua/nvim-tree/actions/find-file.lua @@ -6,18 +6,19 @@ local renderer = require"nvim-tree.renderer" local M = {} -function M.fn(fname) - local i +local function get_index_offset() local hide_root_folder = view.View.hide_root_folder - if not TreeExplorer then - return - end if TreeExplorer.cwd == '/' or hide_root_folder then - i = 0 + return 0 else - i = 1 + return 1 end +end +function M.fn(fname) + if not TreeExplorer then return end + + local i = get_index_offset() local tree_altered = false local function iterate_nodes(nodes) @@ -27,26 +28,27 @@ function M.fn(fname) return i end - local path_matches = utils.str_find(fname, node.absolute_path..utils.path_separator) + local path_matches = node.nodes and utils.str_find(fname, node.absolute_path..utils.path_separator) if path_matches then - if #node.nodes == 0 then - node.open = true - explorer_module.explore(node, node.absolute_path, {}) - git.load_project_status(node.absolute_path, function(status) - if status.dirs or status.files then - require"nvim-tree.actions.reloaders".reload_node_status(node, git.projects) - end - renderer.draw() - end) - end - if node.open == false then + if not node.open then node.open = true tree_altered = true end + + if #node.nodes == 0 then + local git_finished = false + git.load_project_status(node.absolute_path, function(status) + explorer_module.explore(node, node.absolute_path, status) + git_finished = true + end) + while not vim.wait(10, function() return git_finished end, 10) do end + end + if iterate_nodes(node.nodes) ~= nil then return i end - elseif node.open == true then + -- mandatory to iterate i + elseif node.open then iterate_nodes(node.nodes) end end