refactor: take single opts param on node navigation (#2584)
* refactor: take single `opts` param on node navigation * `MoveOpts` -> `NavigationItemOpts`
This commit is contained in:
@@ -6,19 +6,22 @@ local explorer_node = require "nvim-tree.explorer.node"
|
||||
|
||||
local M = {}
|
||||
|
||||
---@param where string
|
||||
---@param what string
|
||||
---@class NavigationItemOpts
|
||||
---@field where string
|
||||
---@field what string
|
||||
|
||||
---@param opts NavigationItemOpts
|
||||
---@return fun()
|
||||
function M.fn(where, what)
|
||||
function M.fn(opts)
|
||||
return function()
|
||||
local node_cur = lib.get_node_at_cursor()
|
||||
local first_node_line = core.get_nodes_starting_line()
|
||||
local nodes_by_line = utils.get_nodes_by_line(core.get_explorer().nodes, first_node_line)
|
||||
local iter_start, iter_end, iter_step, cur, first, nex
|
||||
|
||||
if where == "next" then
|
||||
if opts.where == "next" then
|
||||
iter_start, iter_end, iter_step = first_node_line, #nodes_by_line, 1
|
||||
elseif where == "prev" then
|
||||
elseif opts.where == "prev" then
|
||||
iter_start, iter_end, iter_step = #nodes_by_line, first_node_line, -1
|
||||
end
|
||||
|
||||
@@ -26,11 +29,11 @@ function M.fn(where, what)
|
||||
local node = nodes_by_line[line]
|
||||
local valid = false
|
||||
|
||||
if what == "git" then
|
||||
if opts.what == "git" then
|
||||
valid = explorer_node.get_git_status(node) ~= nil
|
||||
elseif what == "diag" then
|
||||
elseif opts.what == "diag" then
|
||||
valid = node.diag_status ~= nil
|
||||
elseif what == "opened" then
|
||||
elseif opts.what == "opened" then
|
||||
valid = vim.fn.bufloaded(node.absolute_path) ~= 0
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user