move expand_or_collapse to DirectoryNode
This commit is contained in:
@@ -4,6 +4,8 @@ local core = require("nvim-tree.core")
|
|||||||
local lib = require("nvim-tree.lib")
|
local lib = require("nvim-tree.lib")
|
||||||
local diagnostics = require("nvim-tree.diagnostics")
|
local diagnostics = require("nvim-tree.diagnostics")
|
||||||
|
|
||||||
|
local DirectoryNode = require("nvim-tree.node.directory")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
local MAX_DEPTH = 100
|
local MAX_DEPTH = 100
|
||||||
|
|
||||||
@@ -70,8 +72,10 @@ local function move(where, what, skip_gitignored)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param node Node
|
||||||
local function expand_node(node)
|
local function expand_node(node)
|
||||||
if not node.open then
|
if node:is(DirectoryNode) and not node.open then
|
||||||
|
---@cast node DirectoryNode
|
||||||
-- Expand the node.
|
-- Expand the node.
|
||||||
-- Should never collapse since we checked open.
|
-- Should never collapse since we checked open.
|
||||||
node:expand_or_collapse()
|
node:expand_or_collapse()
|
||||||
@@ -96,7 +100,8 @@ local function move_next_recursive(what, skip_gitignored)
|
|||||||
if node_init.name ~= ".." then -- root node cannot have a status
|
if node_init.name ~= ".." then -- root node cannot have a status
|
||||||
valid = status_is_valid(node_init, what, skip_gitignored)
|
valid = status_is_valid(node_init, what, skip_gitignored)
|
||||||
end
|
end
|
||||||
if node_init.nodes ~= nil and valid and not node_init.open then
|
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()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ local help = require("nvim-tree.help")
|
|||||||
local keymap = require("nvim-tree.keymap")
|
local keymap = require("nvim-tree.keymap")
|
||||||
local notify = require("nvim-tree.notify")
|
local notify = require("nvim-tree.notify")
|
||||||
|
|
||||||
|
local DirectoryNode = require("nvim-tree.node.directory")
|
||||||
|
|
||||||
local Api = {
|
local Api = {
|
||||||
tree = {},
|
tree = {},
|
||||||
node = {
|
node = {
|
||||||
@@ -213,7 +215,8 @@ local function open_or_expand_or_dir_up(mode, toggle_group)
|
|||||||
return function(node)
|
return function(node)
|
||||||
if node.name == ".." then
|
if node.name == ".." then
|
||||||
actions.root.change_dir.fn("..")
|
actions.root.change_dir.fn("..")
|
||||||
elseif node.nodes then
|
elseif node:is(DirectoryNode) then
|
||||||
|
---@cast node DirectoryNode
|
||||||
node:expand_or_collapse(toggle_group)
|
node:expand_or_collapse(toggle_group)
|
||||||
elseif not toggle_group then
|
elseif not toggle_group then
|
||||||
edit(mode, node)
|
edit(mode, node)
|
||||||
|
|||||||
@@ -116,6 +116,35 @@ function DirectoryNode:get_git_status()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function DirectoryNode:expand_or_collapse(toggle_group)
|
||||||
|
toggle_group = toggle_group or false
|
||||||
|
if self.has_children then
|
||||||
|
self.has_children = false
|
||||||
|
end
|
||||||
|
|
||||||
|
if #self.nodes == 0 then
|
||||||
|
self.explorer:expand(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
local head_node = self:get_parent_of_group()
|
||||||
|
if toggle_group then
|
||||||
|
head_node:toggle_group_folders()
|
||||||
|
end
|
||||||
|
|
||||||
|
local open = self:last_group_node().open
|
||||||
|
local next_open
|
||||||
|
if toggle_group then
|
||||||
|
next_open = open
|
||||||
|
else
|
||||||
|
next_open = not open
|
||||||
|
end
|
||||||
|
for _, n in ipairs(head_node:get_all_nodes_in_group()) do
|
||||||
|
n.open = next_open
|
||||||
|
end
|
||||||
|
|
||||||
|
self.explorer.renderer:draw()
|
||||||
|
end
|
||||||
|
|
||||||
---Create a sanitized partial copy of a node, populating children recursively.
|
---Create a sanitized partial copy of a node, populating children recursively.
|
||||||
---@return DirectoryNode cloned
|
---@return DirectoryNode cloned
|
||||||
function DirectoryNode:clone()
|
function DirectoryNode:clone()
|
||||||
|
|||||||
@@ -225,36 +225,6 @@ function BaseNode:ungroup_empty_folders()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function BaseNode:expand_or_collapse(toggle_group)
|
|
||||||
toggle_group = toggle_group or false
|
|
||||||
if self.has_children then
|
|
||||||
---@cast self DirectoryNode -- TODO #2886 move this to the class
|
|
||||||
self.has_children = false
|
|
||||||
end
|
|
||||||
|
|
||||||
if #self.nodes == 0 then
|
|
||||||
self.explorer:expand(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
local head_node = self:get_parent_of_group()
|
|
||||||
if toggle_group then
|
|
||||||
head_node:toggle_group_folders()
|
|
||||||
end
|
|
||||||
|
|
||||||
local open = self:last_group_node().open
|
|
||||||
local next_open
|
|
||||||
if toggle_group then
|
|
||||||
next_open = open
|
|
||||||
else
|
|
||||||
next_open = not open
|
|
||||||
end
|
|
||||||
for _, n in ipairs(head_node:get_all_nodes_in_group()) do
|
|
||||||
n.open = next_open
|
|
||||||
end
|
|
||||||
|
|
||||||
self.explorer.renderer:draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
---Create a sanitized partial copy of a node, populating children recursively.
|
---Create a sanitized partial copy of a node, populating children recursively.
|
||||||
---@return BaseNode cloned
|
---@return BaseNode cloned
|
||||||
function BaseNode:clone()
|
function BaseNode:clone()
|
||||||
|
|||||||
Reference in New Issue
Block a user