diff --git a/lua/lib/lib.lua b/lua/lib/lib.lua index 6d5ba4d9..a07613ab 100644 --- a/lua/lib/lib.lua +++ b/lua/lib/lib.lua @@ -92,6 +92,7 @@ end function M.unroll_dir(node) node.open = not node.open + if node.children_initial then node.children_initial = false end if #node.entries > 0 then renderer.draw(M.Tree, true) else diff --git a/lua/lib/populate.lua b/lua/lib/populate.lua index d9f8940d..d62b8c55 100644 --- a/lua/lib/populate.lua +++ b/lua/lib/populate.lua @@ -15,9 +15,8 @@ local path_to_matching_str = require'lib.utils'.path_to_matching_str local function dir_new(cwd, name) local absolute_path = cwd..'/'..name local stat = luv.fs_stat(absolute_path) - local handle = luv.fs_opendir(absolute_path, nil, 1) - local child = luv.fs_readdir(handle) - luv.fs_closedir(handle) + local handle = luv.fs_scandir(absolute_path) + local has_children = luv.fs_scandir_next(handle) ~= nil return { name = name, absolute_path = absolute_path, @@ -26,7 +25,7 @@ local function dir_new(cwd, name) match_name = path_to_matching_str(name), match_path = path_to_matching_str(absolute_path), open = false, - has_children = child ~= nil, + children_initial = has_children, entries = {} } end diff --git a/lua/lib/renderer.lua b/lua/lib/renderer.lua index 1b019620..d790d746 100644 --- a/lua/lib/renderer.lua +++ b/lua/lib/renderer.lua @@ -238,8 +238,7 @@ local function update_draw_data(tree, depth, markers) local git_hl = get_git_hl(node) if node.entries then - local icon = get_folder_icon(node.open, node.link_to ~= nil, #node.entries ~= 0 or node.has_children) - if node.has_children then node.has_children = nil end + local icon = get_folder_icon(node.open, node.link_to ~= nil, #node.entries ~= 0 or node.children_initial) local git_icon = get_git_icons(node, index, offset, #icon+1) or "" -- INFO: this is mandatory in order to keep gui attributes (bold/italics) set_folder_hl(index, offset, #icon, #node.name+#git_icon, 'NvimTreeFolderName')