Skip to content

feat: add hide_root_folder #728

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 9 commits into from
Oct 24, 2021
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ require'nvim-tree'.setup {
width = 30,
-- height of the window, can be either a number (columns) or a string in `%`, for top or bottom side placement
height = 30,
-- Hide the root path of the current folder on top of the tree
hide_root_folder = false,
-- side of the tree, can be one of 'left' | 'right' | 'top' | 'bottom'
side = 'left',
-- if true the tree will resize itself after opening a file
Expand Down
5 changes: 5 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ Here is a list of the options available in the setup call:
*nvim-tree.view*
- |view|: window / buffer setup

- |view.hide_root_folder|: hide the path of the current working
directory on top of the tree
type: `boolean`
default: `false`

- |view.width|: width of the window, can be either a `%` string or
a number representing columns. Only works with |view.side| `left` or `right`
type: `string | number`
Expand Down
1 change: 1 addition & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ local DEFAULT_OPTS = {
auto_close = false,
hijack_cursor = false,
update_cwd = false,
hide_root_folder = false,
update_focused_file = {
enable = false,
update_cwd = false,
Expand Down
8 changes: 5 additions & 3 deletions lua/nvim-tree/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function M.redraw()
end

local function get_node_at_line(line)
local index = 2
local index = view.View.hide_root_folder and 1 or 2
local function iter(entries)
for _, node in ipairs(entries) do
if index == line then
Expand Down Expand Up @@ -101,6 +101,7 @@ end

function M.get_node_at_cursor()
local winnr = view.get_winnr()
local hide_root_folder = view.View.hide_root_folder
if not winnr then
return
end
Expand All @@ -111,7 +112,7 @@ function M.get_node_at_cursor()
local help_text = get_node_at_line(line+1)(help_lines)
return {name = help_text}
else
if line == 1 and M.Tree.cwd ~= "/" then
if line == 1 and M.Tree.cwd ~= "/" and not hide_root_folder then
return { name = ".." }
end

Expand Down Expand Up @@ -204,7 +205,8 @@ end

function M.set_index_and_redraw(fname)
local i
if M.Tree.cwd == '/' then
local hide_root_folder = view.View.hide_root_folder
if M.Tree.cwd == '/' or hide_root_folder then
i = 0
else
i = 1
Expand Down
4 changes: 3 additions & 1 deletion lua/nvim-tree/renderer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ local function update_draw_data(tree, depth, markers)
["readme.md"] = true,
}

if tree.cwd and tree.cwd ~= '/' then
local hide_root_folder = view.View.hide_root_folder

if tree.cwd and tree.cwd ~= '/' and not hide_root_folder then
local root_name = utils.path_join({
utils.path_remove_trailing(vim.fn.fnamemodify(tree.cwd, root_folder_modifier)),
".."
Expand Down
2 changes: 2 additions & 0 deletions lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ end
M.View = {
bufnr = nil,
tabpages = {},
hide_root_folder = false,
winopts = {
relativenumber = false,
number = false,
Expand Down Expand Up @@ -144,6 +145,7 @@ function M.setup(opts)
M.View.side = options.side
M.View.width = options.width
M.View.height = options.height
M.View.hide_root_folder = options.hide_root_folder
M.View.auto_resize = opts.auto_resize
if options.mappings.custom_only then
M.View.mappings = options.mappings.list
Expand Down