refactor(#2886): multi instance: node class refactoring (#2950)

* add todo

* refactor(#2886): multi instance: node class refactoring: extract links, *_git_status (#2944)

* extract DirectoryLinkNode and FileLinkNode, move Node methods to children

* temporarily move DirectoryNode methods into BaseNode for easier reviewing

* move mostly unchanged DirectoryNode methods back to BaseNode

* tidy

* git.git_status_file takes an array

* update git status of links

* luacheck hack

* safer git_status_dir

* refactor(#2886): multi instance: node class refactoring: DirectoryNode:expand_or_collapse (#2957)

move expand_or_collapse to DirectoryNode

* 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

* more type safety
This commit is contained in:
Alexander Courtis
2024-10-25 12:24:59 +11:00
committed by GitHub
parent 63c7ad9037
commit 68be6df2fc
25 changed files with 591 additions and 482 deletions

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