refactor(#2942): multi instance: move find_node_line to Explorer

This commit is contained in:
Alexander Courtis 2025-09-08 14:57:49 +10:00
parent f92cc3a91c
commit d087a8204d
3 changed files with 22 additions and 23 deletions

View File

@ -191,7 +191,7 @@ local function move_prev_recursive(explorer, what, skip_gitignored)
if node_init.name == ".." then -- root node if node_init.name == ".." then -- root node
view.set_cursor({ 1, 0 }) -- move to root node (position 1) view.set_cursor({ 1, 0 }) -- move to root node (position 1)
else else
local node_init_line = utils.find_node_line(node_init) local node_init_line = explorer:find_node_line(node_init)
if node_init_line < 0 then if node_init_line < 0 then
return return
end end

View File

@ -551,6 +551,27 @@ function Explorer:place_cursor_on_node()
end end
end end
-- Find the line number of a node.
---@param node Node?
---@return integer -1 not found
function Explorer:find_node_line(node)
if not node then
return -1
end
local first_node_line = core.get_nodes_starting_line()
local nodes_by_line = utils.get_nodes_by_line(self.nodes, first_node_line)
local iter_start, iter_end = first_node_line, #nodes_by_line
for line = iter_start, iter_end, 1 do
if nodes_by_line[line] == node then
return line
end
end
return -1
end
---Api.tree.get_nodes ---Api.tree.get_nodes
---@return nvim_tree.api.Node ---@return nvim_tree.api.Node
function Explorer:get_nodes() function Explorer:get_nodes()

View File

@ -134,28 +134,6 @@ function M.find_node(nodes, fn)
return node, i return node, i
end end
-- Find the line number of a node.
-- Return -1 is node is nil or not found.
---@param node Node?
---@return integer
function M.find_node_line(node)
if not node then
return -1
end
local first_node_line = require("nvim-tree.core").get_nodes_starting_line()
local nodes_by_line = M.get_nodes_by_line(require("nvim-tree.core").get_explorer().nodes, first_node_line)
local iter_start, iter_end = first_node_line, #nodes_by_line
for line = iter_start, iter_end, 1 do
if nodes_by_line[line] == node then
return line
end
end
return -1
end
---@param extmarks vim.api.keyset.get_extmark_item[] as per vim.api.nvim_buf_get_extmarks ---@param extmarks vim.api.keyset.get_extmark_item[] as per vim.api.nvim_buf_get_extmarks
---@return number ---@return number
function M.extmarks_length(extmarks) function M.extmarks_length(extmarks)