|
1 | 1 | local Iterator = require("nvim-tree.iterators.node-iterator") |
2 | 2 | local notify = require("nvim-tree.notify") |
3 | 3 |
|
| 4 | +local DirectoryNode = require("nvim-tree.node.directory") |
| 5 | + |
4 | 6 | local M = { |
5 | 7 | debouncers = {}, |
6 | 8 | } |
@@ -124,7 +126,12 @@ function M.find_node(nodes, fn) |
124 | 126 | local node, i = Iterator.builder(nodes) |
125 | 127 | :matcher(fn) |
126 | 128 | :recursor(function(node) |
127 | | - return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes) |
| 129 | + local dir = node:as(DirectoryNode) |
| 130 | + if dir then |
| 131 | + return dir.group_next and { dir.group_next } or (dir.open and #dir.nodes > 0 and dir.nodes) |
| 132 | + else |
| 133 | + return false |
| 134 | + end |
128 | 135 | end) |
129 | 136 | :iterate() |
130 | 137 | 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) |
179 | 186 | return node.absolute_path == path or node.link_to == path |
180 | 187 | end) |
181 | 188 | :recursor(function(node) |
182 | | - if node.group_next then |
183 | | - return { node.group_next } |
| 189 | + local dir = node:as(DirectoryNode) |
| 190 | + if dir and dir.group_next then |
| 191 | + return { dir.group_next } |
184 | 192 | end |
185 | | - if node.nodes then |
186 | | - return node.nodes |
| 193 | + if dir then |
| 194 | + return dir.nodes |
187 | 195 | end |
188 | 196 | end) |
189 | 197 | :iterate() |
@@ -219,14 +227,20 @@ function M.get_nodes_by_line(nodes_all, line_start) |
219 | 227 |
|
220 | 228 | Iterator.builder(nodes_all) |
221 | 229 | :applier(function(node) |
222 | | - if node.group_next then |
| 230 | + local dir = node:as(DirectoryNode) |
| 231 | + if dir and dir.group_next then |
223 | 232 | return |
224 | 233 | end |
225 | 234 | nodes_by_line[line] = node |
226 | 235 | line = line + 1 |
227 | 236 | end) |
228 | 237 | :recursor(function(node) |
229 | | - return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes) |
| 238 | + local dir = node:as(DirectoryNode) |
| 239 | + if dir then |
| 240 | + return dir.group_next and { dir.group_next } or (dir.open and #dir.nodes > 0 and dir.nodes) |
| 241 | + else |
| 242 | + return false |
| 243 | + end |
230 | 244 | end) |
231 | 245 | :iterate() |
232 | 246 |
|
|
0 commit comments