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

@@ -7,6 +7,8 @@ local notify = require("nvim-tree.notify")
local find_file = require("nvim-tree.actions.finders.find-file").fn
local DirectoryNode = require("nvim-tree.node.directory")
---@enum ACTION
local ACTION = {
copy = "copy",
@@ -219,7 +221,7 @@ end
function Clipboard:do_paste(node, action, action_fn)
if node.name == ".." then
node = self.explorer
else
elseif node:is(DirectoryNode) then
node = node:last_group_node()
end
local clip = self.data[action]

View File

@@ -5,6 +5,9 @@ local notify = require("nvim-tree.notify")
local find_file = require("nvim-tree.actions.finders.find-file").fn
local FileNode = require("nvim-tree.node.file")
local DirectoryNode = require("nvim-tree.node.directory")
local M = {}
---@param file string
@@ -29,35 +32,21 @@ local function get_num_nodes(iter)
return i
end
---@param node Node
---@return string
local function get_containing_folder(node)
if node.nodes ~= nil then
return utils.path_add_trailing(node.absolute_path)
end
local node_name_size = #(node.name or "")
return node.absolute_path:sub(0, -node_name_size - 1)
end
---@param node Node?
function M.fn(node)
local cwd = core.get_cwd()
if cwd == nil then
node = node or core.get_explorer() --[[@as Node]]
if not node then
return
end
if not node or node.name == ".." then
node = {
absolute_path = cwd,
name = "",
nodes = core.get_explorer().nodes,
open = true,
}
else
node = node:last_group_node()
local dir = node:is(FileNode) and node.parent or node:as(DirectoryNode)
if not dir then
return
end
local containing_folder = get_containing_folder(node)
dir = dir:last_group_node()
local containing_folder = utils.path_add_trailing(dir.absolute_path)
local input_opts = {
prompt = "Create file ",

View File

@@ -6,6 +6,8 @@ local notify = require("nvim-tree.notify")
local find_file = require("nvim-tree.actions.finders.find-file").fn
local DirectoryNode = require("nvim-tree.node.directory")
local M = {
config = {},
}
@@ -120,7 +122,9 @@ function M.fn(default_modifier)
return
end
node = node:last_group_node()
if node:is(DirectoryNode) then
node = node:last_group_node()
end
if node.name == ".." then
return
end