Skip to content

fix: correct index in movement actions #1058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions lua/nvim-tree/actions/find-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion lua/nvim-tree/actions/movements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/search-node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions lua/nvim-tree/renderer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ local function update_draw_data(tree, depth, markers)
["readme.md"] = true,
}

local hide_root_folder = view.View.hide_root_folder

if tree.cwd and tree.cwd ~= "/" and not hide_root_folder then
if view.is_root_folder_visible(tree) then
local root_name = utils.path_join {
utils.path_remove_trailing(vim.fn.fnamemodify(tree.cwd, root_folder_modifier)),
"..",
Expand Down
4 changes: 4 additions & 0 deletions lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ function M._prevent_buffer_override()
end)
end

function M.is_root_folder_visible(tree)
return tree.cwd and tree.cwd ~= "/" and not M.View.hide_root_folder
end

local DEFAULT_CONFIG = {
width = 30,
height = 30,
Expand Down