#972 bug: prev_git_item with hijack_cursor selects icon instead of previous file (#1025)

This commit is contained in:
Alexander Courtis
2022-03-01 07:31:23 +11:00
committed by GitHub
parent 48e76bc031
commit ce3604d33c
2 changed files with 47 additions and 15 deletions

View File

@@ -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