This commit is contained in:
parent
48e76bc031
commit
ce3604d33c
@ -1,7 +1,6 @@
|
||||
local utils = require'nvim-tree.utils'
|
||||
local view = require'nvim-tree.view'
|
||||
local diagnostics = require'nvim-tree.diagnostics'
|
||||
local _icons = require"nvim-tree.renderer.icons"
|
||||
local renderer = require"nvim-tree.renderer"
|
||||
local lib = function() return require'nvim-tree.lib' end
|
||||
|
||||
@ -106,11 +105,42 @@ function M.sibling(direction)
|
||||
end
|
||||
|
||||
function M.find_git_item(where)
|
||||
local icon_state = _icons.get_config()
|
||||
local flags = where == 'prev' and 'b' or ''
|
||||
local icons = table.concat(vim.tbl_values(icon_state.icons.git_icons), '\\|')
|
||||
return function()
|
||||
return icon_state.show_git_icon and vim.fn.search(icons, flags)
|
||||
local node_cur = lib().get_node_at_cursor()
|
||||
local nodes_by_line = lib().get_nodes_by_line(TreeExplorer.nodes, view.View.hide_root_folder and 1 or 2)
|
||||
|
||||
local cur, first, prev, nex = nil, nil, nil, nil
|
||||
for line, node in pairs(nodes_by_line) do
|
||||
if not first and node.git_status then
|
||||
first = line
|
||||
end
|
||||
|
||||
if node == node_cur then
|
||||
cur = line
|
||||
elseif node.git_status then
|
||||
if not cur then
|
||||
prev = line
|
||||
end
|
||||
if cur and not nex then
|
||||
nex = line
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if where == 'prev' then
|
||||
if prev then
|
||||
view.set_cursor({prev, 0})
|
||||
end
|
||||
else
|
||||
if cur then
|
||||
if nex then
|
||||
view.set_cursor({nex, 0})
|
||||
end
|
||||
elseif first then
|
||||
view.set_cursor({first, 0})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -22,21 +22,23 @@ function M.init(foldername)
|
||||
end
|
||||
end
|
||||
|
||||
local function get_node_at_line(line)
|
||||
local index = view.View.hide_root_folder and 1 or 2
|
||||
function M.get_nodes_by_line(nodes_all, line_start)
|
||||
local nodes_by_line = {}
|
||||
local line = line_start
|
||||
local function iter(nodes)
|
||||
for _, node in ipairs(nodes) do
|
||||
if index == line then
|
||||
return node
|
||||
end
|
||||
index = index + 1
|
||||
nodes_by_line[line] = node
|
||||
line = line + 1
|
||||
if node.open == true then
|
||||
local child = iter(node.nodes)
|
||||
if child ~= nil then return child end
|
||||
if child ~= nil then
|
||||
return child
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return iter
|
||||
iter(nodes_all)
|
||||
return nodes_by_line
|
||||
end
|
||||
|
||||
function M.get_node_at_cursor()
|
||||
@ -50,7 +52,7 @@ function M.get_node_at_cursor()
|
||||
local line = cursor[1]
|
||||
if view.is_help_ui() then
|
||||
local help_lines = require'nvim-tree.renderer.help'.compute_lines()
|
||||
local help_text = get_node_at_line(line+1)(help_lines)
|
||||
local help_text = M.get_nodes_by_line(help_lines, 1)[line]
|
||||
return {name = help_text}
|
||||
else
|
||||
if line == 1 and TreeExplorer.cwd ~= "/" and not hide_root_folder then
|
||||
@ -60,7 +62,7 @@ function M.get_node_at_cursor()
|
||||
if TreeExplorer.cwd == "/" then
|
||||
line = line + 1
|
||||
end
|
||||
return get_node_at_line(line)(TreeExplorer.nodes)
|
||||
return M.get_nodes_by_line(TreeExplorer.nodes, view.View.hide_root_folder and 1 or 2)[line]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user