Skip to content

Commit d8b154c

Browse files
fix(#2154): find_file doesn't work when group_empty option is enabled (#2100)
Co-authored-by: Alexander Courtis <[email protected]>
1 parent 74996b8 commit d8b154c

File tree

8 files changed

+28
-16
lines changed

8 files changed

+28
-16
lines changed

lua/nvim-tree/actions/finders/find-file.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ function M.fn(path)
4444
return node.absolute_path == path_real or node.link_to == path_real
4545
end)
4646
:applier(function(node)
47-
line = line + 1
47+
if not node.group_next then
48+
line = line + 1
49+
end
4850

4951
if vim.tbl_contains(absolute_paths_searched, node.absolute_path) then
5052
return
@@ -55,14 +57,16 @@ function M.fn(path)
5557
local link_match = node.link_to and vim.startswith(path_real, node.link_to .. utils.path_separator)
5658

5759
if abs_match or link_match then
58-
node.open = true
60+
if not node.group_next then
61+
node.open = true
62+
end
5963
if #node.nodes == 0 then
6064
core.get_explorer():expand(node)
6165
end
6266
end
6367
end)
6468
:recursor(function(node)
65-
return node.open and node.nodes
69+
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
6670
end)
6771
:iterate()
6872

lua/nvim-tree/actions/moves/parent.lua

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@ local renderer = require "nvim-tree.renderer"
22
local view = require "nvim-tree.view"
33
local utils = require "nvim-tree.utils"
44
local core = require "nvim-tree.core"
5+
local lib = require "nvim-tree.lib"
56

67
local M = {}
78

89
function M.fn(should_close)
910
should_close = should_close or false
1011

1112
return function(node)
13+
node = lib.get_last_group_node(node)
1214
if should_close and node.open then
1315
node.open = false
1416
return renderer.draw()
1517
end
1618

17-
local parent = node.parent
18-
19-
if renderer.config.group_empty and parent then
20-
while parent.parent and parent.parent.group_next do
21-
parent = parent.parent
22-
end
23-
end
19+
local parent = utils.get_parent_of_group(node).parent
2420

2521
if not parent or not parent.parent then
2622
return view.set_cursor { 1, 0 }

lua/nvim-tree/actions/tree-modifiers/collapse-all.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function M.fn(keep_buffers)
3636
end
3737
end)
3838
:recursor(function(n)
39-
return n.nodes
39+
return n.group_next and { n.group_next } or n.nodes
4040
end)
4141
:iterate()
4242

lua/nvim-tree/actions/tree-modifiers/expand-all.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local core = require "nvim-tree.core"
22
local renderer = require "nvim-tree.renderer"
33
local Iterator = require "nvim-tree.iterators.node-iterator"
44
local notify = require "nvim-tree.notify"
5+
local lib = require "nvim-tree.lib"
56

67
local M = {}
78

@@ -15,6 +16,7 @@ local function to_lookup_table(list)
1516
end
1617

1718
local function expand(node)
19+
node = lib.get_last_group_node(node)
1820
node.open = true
1921
if #node.nodes == 0 then
2022
core.get_explorer():expand(node)
@@ -45,7 +47,8 @@ local function gen_iterator()
4547
end
4648
end)
4749
:recursor(function(node)
48-
return expansion_count < M.MAX_FOLDER_DISCOVERY and node.open and node.nodes
50+
return expansion_count < M.MAX_FOLDER_DISCOVERY
51+
and (node.group_next and { node.group_next } or (node.open and node.nodes))
4952
end)
5053
:iterate()
5154

lua/nvim-tree/iterators/node-iterator.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ function NodeIterator:iterate()
4242
local function iter(nodes)
4343
for _, node in ipairs(nodes) do
4444
if self._filter_hidden(node) then
45-
iteration_count = iteration_count + 1
45+
if not node.group_next then
46+
iteration_count = iteration_count + 1
47+
end
4648
if self._match(node) then
4749
return node, iteration_count
4850
end

lua/nvim-tree/lib.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ function M.get_last_group_node(node)
8181
end
8282

8383
function M.expand_or_collapse(node)
84-
node.open = not node.open
8584
if node.has_children then
8685
node.has_children = false
8786
end
@@ -90,6 +89,9 @@ function M.expand_or_collapse(node)
9089
core.get_explorer():expand(node)
9190
end
9291

92+
node = M.get_last_group_node(node)
93+
node.open = not node.open
94+
9395
renderer.draw()
9496
end
9597

lua/nvim-tree/renderer/builder.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
341341

342342
self.index = self.index + 1
343343

344+
node = require("nvim-tree.lib").get_last_group_node(node)
345+
344346
if node.open then
345347
self.depth = self.depth + 1
346348
self:build(node, unloaded_bufnr)

lua/nvim-tree/utils.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function M.find_node(nodes, fn)
8989
local node, i = Iterator.builder(nodes)
9090
:matcher(fn)
9191
:recursor(function(node)
92-
return node.open and #node.nodes > 0 and node.nodes
92+
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
9393
end)
9494
:iterate()
9595
i = require("nvim-tree.view").is_root_folder_visible() and i or i - 1
@@ -146,11 +146,14 @@ function M.get_nodes_by_line(nodes_all, line_start)
146146

147147
Iterator.builder(nodes_all)
148148
:applier(function(node)
149+
if node.group_next then
150+
return
151+
end
149152
nodes_by_line[line] = node
150153
line = line + 1
151154
end)
152155
:recursor(function(node)
153-
return node.open == true and node.nodes
156+
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
154157
end)
155158
:iterate()
156159

0 commit comments

Comments
 (0)