* refactor(#2942): multi instance: move find_node_line to Explorer * refactor(#2942): multi instance: move get_node_from_path to Explorer * refactor(#2942): multi instance: move focus_file to Explorer * refactor(#2942): multi instance: move focus_node_or_parent to Explorer * refactor(#2942): multi instance: move get_node_from_path to Explorer * refactor(#2942): multi instance: move find_node to Explorer * refactor(#2942): multi instance: move get_nodes_by_line to Explorer * refactor(#2942): multi instance: remove unnecessary focus_file * refactor(#2942): style
58 lines
1.3 KiB
Lua
58 lines
1.3 KiB
Lua
local core = require("nvim-tree.core")
|
|
local Iterator = require("nvim-tree.iterators.node-iterator")
|
|
|
|
local M = {}
|
|
|
|
---@param direction string
|
|
---@return fun(node: Node): nil
|
|
function M.fn(direction)
|
|
return function(node)
|
|
if node.name == ".." or not direction then
|
|
return
|
|
end
|
|
|
|
local explorer = core.get_explorer()
|
|
if not explorer then
|
|
return
|
|
end
|
|
|
|
local first, last, next, prev = nil, nil, nil, nil
|
|
local found = false
|
|
local parent = node.parent or explorer
|
|
Iterator.builder(parent and parent.nodes or {})
|
|
:recursor(function()
|
|
return nil
|
|
end)
|
|
:applier(function(n)
|
|
first = first or n
|
|
last = n
|
|
if n.absolute_path == node.absolute_path then
|
|
found = true
|
|
return
|
|
end
|
|
prev = not found and n or prev
|
|
if found and not next then
|
|
next = n
|
|
end
|
|
end)
|
|
:iterate()
|
|
|
|
local target_node
|
|
if direction == "first" then
|
|
target_node = first
|
|
elseif direction == "last" then
|
|
target_node = last
|
|
elseif direction == "next" then
|
|
target_node = next or first
|
|
else
|
|
target_node = prev or last
|
|
end
|
|
|
|
if target_node then
|
|
explorer:focus_node_or_parent(target_node)
|
|
end
|
|
end
|
|
end
|
|
|
|
return M
|