chore: resolve undefined-field

This commit is contained in:
Alexander Courtis
2024-10-25 15:18:58 +11:00
parent 64e0c90183
commit 6aba4a8a16

View File

@@ -1,6 +1,8 @@
local Iterator = require("nvim-tree.iterators.node-iterator")
local notify = require("nvim-tree.notify")
local DirectoryNode = require("nvim-tree.node.directory")
local M = {
debouncers = {},
}
@@ -124,7 +126,12 @@ function M.find_node(nodes, fn)
local node, i = Iterator.builder(nodes)
:matcher(fn)
:recursor(function(node)
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
local dir = node:as(DirectoryNode)
if dir then
return dir.group_next and { dir.group_next } or (dir.open and #dir.nodes > 0 and dir.nodes)
else
return false
end
end)
:iterate()
i = require("nvim-tree.view").is_root_folder_visible() and i or i - 1
@@ -179,11 +186,12 @@ function M.get_node_from_path(path)
return node.absolute_path == path or node.link_to == path
end)
:recursor(function(node)
if node.group_next then
return { node.group_next }
local dir = node:as(DirectoryNode)
if dir and dir.group_next then
return { dir.group_next }
end
if node.nodes then
return node.nodes
if dir then
return dir.nodes
end
end)
:iterate()
@@ -219,14 +227,20 @@ function M.get_nodes_by_line(nodes_all, line_start)
Iterator.builder(nodes_all)
:applier(function(node)
if node.group_next then
local dir = node:as(DirectoryNode)
if dir and dir.group_next then
return
end
nodes_by_line[line] = node
line = line + 1
end)
:recursor(function(node)
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
local dir = node:as(DirectoryNode)
if dir then
return dir.group_next and { dir.group_next } or (dir.open and #dir.nodes > 0 and dir.nodes)
else
return false
end
end)
:iterate()