fix(#2154): find_file doesn't work when group_empty option is enabled (#2100)

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Zhanibek Adilbekov
2023-04-29 13:03:20 +06:00
committed by GitHub
parent 74996b8626
commit d8b154c5f0
8 changed files with 28 additions and 16 deletions

View File

@@ -44,7 +44,9 @@ function M.fn(path)
return node.absolute_path == path_real or node.link_to == path_real return node.absolute_path == path_real or node.link_to == path_real
end) end)
:applier(function(node) :applier(function(node)
line = line + 1 if not node.group_next then
line = line + 1
end
if vim.tbl_contains(absolute_paths_searched, node.absolute_path) then if vim.tbl_contains(absolute_paths_searched, node.absolute_path) then
return return
@@ -55,14 +57,16 @@ function M.fn(path)
local link_match = node.link_to and vim.startswith(path_real, node.link_to .. utils.path_separator) local link_match = node.link_to and vim.startswith(path_real, node.link_to .. utils.path_separator)
if abs_match or link_match then if abs_match or link_match then
node.open = true if not node.group_next then
node.open = true
end
if #node.nodes == 0 then if #node.nodes == 0 then
core.get_explorer():expand(node) core.get_explorer():expand(node)
end end
end end
end) end)
:recursor(function(node) :recursor(function(node)
return node.open and node.nodes return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
end) end)
:iterate() :iterate()

View File

@@ -2,6 +2,7 @@ local renderer = require "nvim-tree.renderer"
local view = require "nvim-tree.view" local view = require "nvim-tree.view"
local utils = require "nvim-tree.utils" local utils = require "nvim-tree.utils"
local core = require "nvim-tree.core" local core = require "nvim-tree.core"
local lib = require "nvim-tree.lib"
local M = {} local M = {}
@@ -9,18 +10,13 @@ function M.fn(should_close)
should_close = should_close or false should_close = should_close or false
return function(node) return function(node)
node = lib.get_last_group_node(node)
if should_close and node.open then if should_close and node.open then
node.open = false node.open = false
return renderer.draw() return renderer.draw()
end end
local parent = node.parent local parent = utils.get_parent_of_group(node).parent
if renderer.config.group_empty and parent then
while parent.parent and parent.parent.group_next do
parent = parent.parent
end
end
if not parent or not parent.parent then if not parent or not parent.parent then
return view.set_cursor { 1, 0 } return view.set_cursor { 1, 0 }

View File

@@ -36,7 +36,7 @@ function M.fn(keep_buffers)
end end
end) end)
:recursor(function(n) :recursor(function(n)
return n.nodes return n.group_next and { n.group_next } or n.nodes
end) end)
:iterate() :iterate()

View File

@@ -2,6 +2,7 @@ local core = require "nvim-tree.core"
local renderer = require "nvim-tree.renderer" local renderer = require "nvim-tree.renderer"
local Iterator = require "nvim-tree.iterators.node-iterator" local Iterator = require "nvim-tree.iterators.node-iterator"
local notify = require "nvim-tree.notify" local notify = require "nvim-tree.notify"
local lib = require "nvim-tree.lib"
local M = {} local M = {}
@@ -15,6 +16,7 @@ local function to_lookup_table(list)
end end
local function expand(node) local function expand(node)
node = lib.get_last_group_node(node)
node.open = true node.open = true
if #node.nodes == 0 then if #node.nodes == 0 then
core.get_explorer():expand(node) core.get_explorer():expand(node)
@@ -45,7 +47,8 @@ local function gen_iterator()
end end
end) end)
:recursor(function(node) :recursor(function(node)
return expansion_count < M.MAX_FOLDER_DISCOVERY and node.open and node.nodes return expansion_count < M.MAX_FOLDER_DISCOVERY
and (node.group_next and { node.group_next } or (node.open and node.nodes))
end) end)
:iterate() :iterate()

View File

@@ -42,7 +42,9 @@ function NodeIterator:iterate()
local function iter(nodes) local function iter(nodes)
for _, node in ipairs(nodes) do for _, node in ipairs(nodes) do
if self._filter_hidden(node) then if self._filter_hidden(node) then
iteration_count = iteration_count + 1 if not node.group_next then
iteration_count = iteration_count + 1
end
if self._match(node) then if self._match(node) then
return node, iteration_count return node, iteration_count
end end

View File

@@ -81,7 +81,6 @@ function M.get_last_group_node(node)
end end
function M.expand_or_collapse(node) function M.expand_or_collapse(node)
node.open = not node.open
if node.has_children then if node.has_children then
node.has_children = false node.has_children = false
end end
@@ -90,6 +89,9 @@ function M.expand_or_collapse(node)
core.get_explorer():expand(node) core.get_explorer():expand(node)
end end
node = M.get_last_group_node(node)
node.open = not node.open
renderer.draw() renderer.draw()
end end

View File

@@ -341,6 +341,8 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
self.index = self.index + 1 self.index = self.index + 1
node = require("nvim-tree.lib").get_last_group_node(node)
if node.open then if node.open then
self.depth = self.depth + 1 self.depth = self.depth + 1
self:build(node, unloaded_bufnr) self:build(node, unloaded_bufnr)

View File

@@ -89,7 +89,7 @@ function M.find_node(nodes, fn)
local node, i = Iterator.builder(nodes) local node, i = Iterator.builder(nodes)
:matcher(fn) :matcher(fn)
:recursor(function(node) :recursor(function(node)
return node.open and #node.nodes > 0 and node.nodes return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
end) end)
:iterate() :iterate()
i = require("nvim-tree.view").is_root_folder_visible() and i or i - 1 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)
Iterator.builder(nodes_all) Iterator.builder(nodes_all)
:applier(function(node) :applier(function(node)
if node.group_next then
return
end
nodes_by_line[line] = node nodes_by_line[line] = node
line = line + 1 line = line + 1
end) end)
:recursor(function(node) :recursor(function(node)
return node.open == true and node.nodes return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
end) end)
:iterate() :iterate()