Skip to content

Commit d5a12ac

Browse files
authored
fix: correct index in movement actions (#1058)
1 parent 08c5766 commit d5a12ac

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

lua/nvim-tree/actions/find-file.lua

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ local renderer = require "nvim-tree.renderer"
44

55
local M = {}
66

7-
local function get_index_offset()
8-
local hide_root_folder = view.View.hide_root_folder
9-
if TreeExplorer.cwd == "/" or hide_root_folder then
10-
return 0
11-
else
12-
return 1
13-
end
14-
end
15-
167
local running = {}
178

189
function M.fn(fname)
@@ -21,7 +12,7 @@ function M.fn(fname)
2112
end
2213
running[fname] = true
2314

24-
local i = get_index_offset()
15+
local i = view.is_root_folder_visible(TreeExplorer) and 1 or 0
2516
local tree_altered = false
2617

2718
local function iterate_nodes(nodes)

lua/nvim-tree/actions/movements.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ function M.parent_node(should_close)
5656
parent.open = false
5757
altered_tree = true
5858
end
59-
line = view.View.hide_root_folder and line - 1 or line
59+
if not view.is_root_folder_visible(TreeExplorer) then
60+
line = line - 1
61+
end
6062
view.set_cursor { line, 0 }
6163
end
6264

@@ -107,6 +109,9 @@ function M.sibling(direction)
107109
local target_node = parent.nodes[index]
108110

109111
line, _ = get_line_from_node(target_node)(TreeExplorer.nodes, true)
112+
if not view.is_root_folder_visible(TreeExplorer) then
113+
line = line - 1
114+
end
110115
view.set_cursor { line, 0 }
111116
end
112117
end

lua/nvim-tree/actions/search-node.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function M.fn()
7777
end
7878

7979
if found_something and view.is_visible() then
80-
if TreeExplorer.cwd ~= "/" and not view.View.hide_root_folder then
80+
if view.is_root_folder_visible(TreeExplorer) then
8181
index = index + 1
8282
end
8383

lua/nvim-tree/renderer/init.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,7 @@ local function update_draw_data(tree, depth, markers)
295295
["readme.md"] = true,
296296
}
297297

298-
local hide_root_folder = view.View.hide_root_folder
299-
300-
if tree.cwd and tree.cwd ~= "/" and not hide_root_folder then
298+
if view.is_root_folder_visible(tree) then
301299
local root_name = utils.path_join {
302300
utils.path_remove_trailing(vim.fn.fnamemodify(tree.cwd, root_folder_modifier)),
303301
"..",

lua/nvim-tree/view.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ function M._prevent_buffer_override()
342342
end)
343343
end
344344

345+
function M.is_root_folder_visible(tree)
346+
return tree.cwd and tree.cwd ~= "/" and not M.View.hide_root_folder
347+
end
348+
345349
local DEFAULT_CONFIG = {
346350
width = 30,
347351
height = 30,

0 commit comments

Comments
 (0)