* chore: add type annotations to (almost) all functions
* stylua
* Add classes for symlink nodes
* Replace deprecated `@vararg`
* Move node classes to `node` module
* Fix `Symlink*` classes
* add vim and libuv runtime for luals, qualify libuv types
* add scripts/luals-check, not quite ready for CI
* additional nil checks for git/init.lua and git/runner.lua
* additional nil checks for nvim-tree.lua
* wrap vim.cmd-as-a-function calls inside functions
* vim.tbl_filter predicate returns booleans
* Revert "add scripts/luals-check, not quite ready for CI"
This reverts commit c70229cad9.
* Add `MinimalNode` class in `marks` module
* Fix various LSP warnings
* stylua
* Fix `Explorer` class, update related annotations and add necessary checks
* Add missing annotations to `live-filter`
* Add temporary aliases for `uv.*` types
* Resolve remaining LSP warnings
* Revert changes not related to internal types
* Minor adjustments
* Update doc comments style
* Minor adjustments (pt. 2)
---------
Co-authored-by: Alexander Courtis <alex@courtis.org>
54 lines
1.2 KiB
Lua
54 lines
1.2 KiB
Lua
local utils = require "nvim-tree.utils"
|
|
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 first, last, next, prev = nil, nil, nil, nil
|
|
local found = false
|
|
local parent = node.parent or core.get_explorer()
|
|
Iterator.builder(parent.nodes)
|
|
: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
|
|
utils.focus_file(target_node.absolute_path)
|
|
end
|
|
end
|
|
end
|
|
|
|
return M
|