#1059 protect against duplicates (#1143)

This commit is contained in:
Alexander Courtis 2022-04-09 22:59:38 +10:00 committed by GitHub
parent deb1f253f4
commit 1bdef08cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 10 deletions

View File

@ -21,9 +21,14 @@ local function populate_children(handle, cwd, node, status)
break break
end end
local nodes_by_path = utils.key_by(node.nodes, "absolute_path")
local abs = utils.path_join { cwd, name } local abs = utils.path_join { cwd, name }
t = get_type_from(t, abs) t = get_type_from(t, abs)
if not filters.should_ignore(abs) and not filters.should_ignore_git(abs, status.files) then if
not filters.should_ignore(abs)
and not filters.should_ignore_git(abs, status.files)
and not nodes_by_path[abs]
then
if t == "directory" and uv.fs_access(abs, "R") then if t == "directory" and uv.fs_access(abs, "R") then
table.insert(node.nodes, builders.folder(abs, name, status, node_ignored)) table.insert(node.nodes, builders.folder(abs, name, status, node_ignored))
elseif t == "file" then elseif t == "file" then

View File

@ -9,14 +9,6 @@ local sorters = require "nvim-tree.explorer.sorters"
local M = {} local M = {}
local function key_by(nodes, key)
local v = {}
for _, node in ipairs(nodes) do
v[node[key]] = node
end
return v
end
local function update_status(nodes_by_path, node_ignored, status) local function update_status(nodes_by_path, node_ignored, status)
return function(node) return function(node)
if nodes_by_path[node.absolute_path] then if nodes_by_path[node.absolute_path] then
@ -46,7 +38,7 @@ function M.reload(node, status)
local child_names = {} local child_names = {}
local node_ignored = node.git_status == "!!" local node_ignored = node.git_status == "!!"
local nodes_by_path = key_by(node.nodes, "absolute_path") local nodes_by_path = utils.key_by(node.nodes, "absolute_path")
while true do while true do
local name, t = uv.fs_scandir_next(handle) local name, t = uv.fs_scandir_next(handle)
if not name then if not name then

View File

@ -210,4 +210,12 @@ function M.format_bytes(bytes)
return (units[pow] == nil) and (bytes .. "B") or (value .. units[pow]) return (units[pow] == nil) and (bytes .. "B") or (value .. units[pow])
end end
function M.key_by(tbl, key)
local keyed = {}
for _, val in ipairs(tbl) do
keyed[val[key]] = val
end
return keyed
end
return M return M