From 4579c6d2b9f386eef9b8f2fe543c3c86c7cc1e17 Mon Sep 17 00:00:00 2001 From: "Cooper b. Anderson" Date: Thu, 18 Feb 2021 05:16:16 -0500 Subject: [PATCH] Make empty dir icons auto update --- lua/lib/fs.lua | 1 + lua/lib/populate.lua | 4 ++-- lua/lib/renderer.lua | 17 +++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lua/lib/fs.lua b/lua/lib/fs.lua index 2793b124..7c6f6d18 100644 --- a/lua/lib/fs.lua +++ b/lua/lib/fs.lua @@ -54,6 +54,7 @@ function M.create(node) if not ans or #ans == 0 then return end if not ans:match('/') then + node.open = true return create_file(add_into..ans) end diff --git a/lua/lib/populate.lua b/lua/lib/populate.lua index de2bc2f5..d9f8940d 100644 --- a/lua/lib/populate.lua +++ b/lua/lib/populate.lua @@ -16,7 +16,7 @@ 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 children = luv.fs_readdir(handle) + local child = luv.fs_readdir(handle) luv.fs_closedir(handle) return { name = name, @@ -26,7 +26,7 @@ local function dir_new(cwd, name) match_name = path_to_matching_str(name), match_path = path_to_matching_str(absolute_path), open = false, - empty = children == nil, + has_children = child ~= nil, entries = {} } end diff --git a/lua/lib/renderer.lua b/lua/lib/renderer.lua index da976b5f..1b019620 100644 --- a/lua/lib/renderer.lua +++ b/lua/lib/renderer.lua @@ -16,21 +16,21 @@ local set_folder_hl = function(line, depth, git_icon_len, _, hl_group) end if icon_state.show_folder_icon then - get_folder_icon = function(open, is_symlink, is_empty) + get_folder_icon = function(open, is_symlink, has_children) local n = "" if is_symlink then n = icon_state.icons.folder_icons.symlink elseif open then - if is_empty then - n = icon_state.icons.folder_icons.empty_open - else + if has_children then n = icon_state.icons.folder_icons.open + else + n = icon_state.icons.folder_icons.empty_open end else - if is_empty then - n = icon_state.icons.folder_icons.empty - else + if has_children then n = icon_state.icons.folder_icons.default + else + n = icon_state.icons.folder_icons.empty end end return n.." " @@ -238,7 +238,8 @@ 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.empty) + 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 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')