refacto: simplify explorer and make it a bit faster

Also fixes #933
This commit is contained in:
kiyan
2022-02-06 18:51:17 +01:00
parent 8a6c7bae3a
commit b76602182f
4 changed files with 25 additions and 73 deletions

View File

@@ -1,4 +1,3 @@
local uv = vim.loop
local utils = require'nvim-tree.utils'
local M = {
@@ -6,25 +5,6 @@ local M = {
exclude_list = {},
}
-- Returns true if there is either exactly 1 dir, or exactly 1 symlink dir. Otherwise, false.
-- @param cwd Absolute path to the parent directory
-- @param dirs List of dir names
-- @param files List of file names
-- @param links List of symlink names
function M.should_group(cwd, dirs, files, links)
if #dirs == 1 and #files == 0 and #links == 0 then
return true
end
if #dirs == 0 and #files == 0 and #links == 1 then
local absolute_path = utils.path_join({ cwd, links[1] })
local link_to = uv.fs_realpath(absolute_path)
return (link_to ~= nil) and uv.fs_stat(link_to).type == 'directory'
end
return false
end
function M.node_comparator(a, b)
if not (a and b) then
return true