fix: correct index in movement actions (#1058)
This commit is contained in:
committed by
GitHub
parent
08c57660a7
commit
d5a12ac9db
@@ -4,15 +4,6 @@ local renderer = require "nvim-tree.renderer"
|
||||
|
||||
local M = {}
|
||||
|
||||
local function get_index_offset()
|
||||
local hide_root_folder = view.View.hide_root_folder
|
||||
if TreeExplorer.cwd == "/" or hide_root_folder then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
local running = {}
|
||||
|
||||
function M.fn(fname)
|
||||
@@ -21,7 +12,7 @@ function M.fn(fname)
|
||||
end
|
||||
running[fname] = true
|
||||
|
||||
local i = get_index_offset()
|
||||
local i = view.is_root_folder_visible(TreeExplorer) and 1 or 0
|
||||
local tree_altered = false
|
||||
|
||||
local function iterate_nodes(nodes)
|
||||
|
||||
@@ -56,7 +56,9 @@ function M.parent_node(should_close)
|
||||
parent.open = false
|
||||
altered_tree = true
|
||||
end
|
||||
line = view.View.hide_root_folder and line - 1 or line
|
||||
if not view.is_root_folder_visible(TreeExplorer) then
|
||||
line = line - 1
|
||||
end
|
||||
view.set_cursor { line, 0 }
|
||||
end
|
||||
|
||||
@@ -107,6 +109,9 @@ function M.sibling(direction)
|
||||
local target_node = parent.nodes[index]
|
||||
|
||||
line, _ = get_line_from_node(target_node)(TreeExplorer.nodes, true)
|
||||
if not view.is_root_folder_visible(TreeExplorer) then
|
||||
line = line - 1
|
||||
end
|
||||
view.set_cursor { line, 0 }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -77,7 +77,7 @@ function M.fn()
|
||||
end
|
||||
|
||||
if found_something and view.is_visible() then
|
||||
if TreeExplorer.cwd ~= "/" and not view.View.hide_root_folder then
|
||||
if view.is_root_folder_visible(TreeExplorer) then
|
||||
index = index + 1
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user