refacto: add get_nodes_starting_line core util

This commit is contained in:
kiyan
2022-03-26 14:46:44 +01:00
parent 20433ced8a
commit 1831417f05
7 changed files with 20 additions and 14 deletions

View File

@@ -38,7 +38,7 @@ function M.force_dirchange(foldername, with_open)
vim.cmd("lcd " .. vim.fn.fnameescape(foldername))
end
end
require("nvim-tree.core").init(foldername)
core.init(foldername)
if with_open then
require("nvim-tree.lib").open()
else

View File

@@ -24,7 +24,7 @@ function M.fn(fname)
return
end
local i = view.is_root_folder_visible() and 1 or 0
local i = core.get_nodes_starting_line() - 1
local tree_altered = false
local function iterate_nodes(nodes)

View File

@@ -17,7 +17,7 @@ local function get_line_from_node(node, find_parent)
node_path = node.absolute_path:match("(.*)" .. utils.path_separator)
end
local line = 2
local line = core.get_nodes_starting_line()
local function iter(nodes, recursive)
for _, _node in ipairs(nodes) do
local n = lib().get_last_group_node(_node)
@@ -58,7 +58,7 @@ function M.parent_node(should_close)
parent.open = false
altered_tree = true
end
if not view.is_root_folder_visible() then
if not view.is_root_folder_visible(core.get_cwd()) then
line = line - 1
end
view.set_cursor { line, 0 }
@@ -111,7 +111,7 @@ function M.sibling(direction)
local target_node = parent.nodes[index]
line, _ = get_line_from_node(target_node)(core.get_explorer().nodes, true)
if not view.is_root_folder_visible() then
if not view.is_root_folder_visible(core.get_cwd()) then
line = line - 1
end
view.set_cursor { line, 0 }
@@ -121,7 +121,7 @@ end
function M.find_git_item(where)
return function()
local node_cur = lib().get_node_at_cursor()
local nodes_by_line = lib().get_nodes_by_line(core.get_explorer().nodes, view.View.hide_root_folder and 1 or 2)
local nodes_by_line = lib().get_nodes_by_line(core.get_explorer().nodes, core.get_nodes_starting_line())
local cur, first, prev, nex = nil, nil, nil, nil
for line, node in pairs(nodes_by_line) do