refactor(#2886): multi instance: node group functions refactoring (#2959)

* move last_group_node to DirectoryNode

* move add BaseNode:as and more doc

* revert parameter name changes

* revert parameter name changes

* add Class

* move group methods into DN

* tidy group methods

* tidy group methods

* tidy group methods

* tidy group methods

* parent is DirectoryNode

* tidy expand all

* BaseNode -> Node

* move watcher to DirectoryNode

* last_group_node is DirectoryNode only

* simplify create-file

* simplify parent

* simplify collapse-all

* simplify live-filter

* style
This commit is contained in:
Alexander Courtis
2024-10-20 17:23:22 +11:00
committed by GitHub
parent fb2070db94
commit 8331a24c77
22 changed files with 284 additions and 258 deletions

View File

@@ -78,7 +78,7 @@ local function expand_node(node)
---@cast node DirectoryNode
-- Expand the node.
-- Should never collapse since we checked open.
node:expand_or_collapse()
node:expand_or_collapse(false)
end
end
@@ -102,7 +102,7 @@ local function move_next_recursive(what, skip_gitignored)
end
if node_init:is(DirectoryNode) and valid and not node_init.open then
---@cast node_init DirectoryNode
node_init:expand_or_collapse()
node_init:expand_or_collapse(false)
end
move("next", what, skip_gitignored)

View File

@@ -1,6 +1,7 @@
local view = require("nvim-tree.view")
local utils = require("nvim-tree.utils")
local core = require("nvim-tree.core")
local DirectoryNode = require("nvim-tree.node.directory")
local M = {}
@@ -9,33 +10,32 @@ local M = {}
function M.fn(should_close)
should_close = should_close or false
---@param node Node
return function(node)
local explorer = core.get_explorer()
node = node:last_group_node()
if should_close and node.open then
node.open = false
if explorer then
explorer.renderer:draw()
local dir = node:as(DirectoryNode)
if dir then
dir = dir:last_group_node()
if should_close and dir.open then
dir.open = false
dir.explorer.renderer:draw()
return
end
return
end
local parent = node:get_parent_of_group().parent
local parent = (node:get_parent_of_group() or node).parent
if not parent or not parent.parent then
return view.set_cursor({ 1, 0 })
end
local _, line = utils.find_node(core.get_explorer().nodes, function(n)
local _, line = utils.find_node(parent.explorer.nodes, function(n)
return n.absolute_path == parent.absolute_path
end)
view.set_cursor({ line + 1, 0 })
if should_close then
parent.open = false
if explorer then
explorer.renderer:draw()
end
parent.explorer.renderer:draw()
end
end
end