feat: add hide_root_folder (#728)
This commit is contained in:
parent
6cadd3a9d7
commit
fd3969ec98
@ -94,6 +94,8 @@ require'nvim-tree'.setup {
|
|||||||
width = 30,
|
width = 30,
|
||||||
-- height of the window, can be either a number (columns) or a string in `%`, for top or bottom side placement
|
-- height of the window, can be either a number (columns) or a string in `%`, for top or bottom side placement
|
||||||
height = 30,
|
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 of the tree, can be one of 'left' | 'right' | 'top' | 'bottom'
|
||||||
side = 'left',
|
side = 'left',
|
||||||
-- if true the tree will resize itself after opening a file
|
-- if true the tree will resize itself after opening a file
|
||||||
|
|||||||
@ -230,6 +230,11 @@ Here is a list of the options available in the setup call:
|
|||||||
*nvim-tree.view*
|
*nvim-tree.view*
|
||||||
- |view|: window / buffer setup
|
- |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
|
- |view.width|: width of the window, can be either a `%` string or
|
||||||
a number representing columns. Only works with |view.side| `left` or `right`
|
a number representing columns. Only works with |view.side| `left` or `right`
|
||||||
type: `string | number`
|
type: `string | number`
|
||||||
|
|||||||
@ -415,6 +415,7 @@ local DEFAULT_OPTS = {
|
|||||||
auto_close = false,
|
auto_close = false,
|
||||||
hijack_cursor = false,
|
hijack_cursor = false,
|
||||||
update_cwd = false,
|
update_cwd = false,
|
||||||
|
hide_root_folder = false,
|
||||||
update_focused_file = {
|
update_focused_file = {
|
||||||
enable = false,
|
enable = false,
|
||||||
update_cwd = false,
|
update_cwd = false,
|
||||||
|
|||||||
@ -58,7 +58,7 @@ function M.redraw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_node_at_line(line)
|
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)
|
local function iter(entries)
|
||||||
for _, node in ipairs(entries) do
|
for _, node in ipairs(entries) do
|
||||||
if index == line then
|
if index == line then
|
||||||
@ -101,6 +101,7 @@ end
|
|||||||
|
|
||||||
function M.get_node_at_cursor()
|
function M.get_node_at_cursor()
|
||||||
local winnr = view.get_winnr()
|
local winnr = view.get_winnr()
|
||||||
|
local hide_root_folder = view.View.hide_root_folder
|
||||||
if not winnr then
|
if not winnr then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -111,7 +112,7 @@ function M.get_node_at_cursor()
|
|||||||
local help_text = get_node_at_line(line+1)(help_lines)
|
local help_text = get_node_at_line(line+1)(help_lines)
|
||||||
return {name = help_text}
|
return {name = help_text}
|
||||||
else
|
else
|
||||||
if line == 1 and M.Tree.cwd ~= "/" then
|
if line == 1 and M.Tree.cwd ~= "/" and not hide_root_folder then
|
||||||
return { name = ".." }
|
return { name = ".." }
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -202,7 +203,8 @@ end
|
|||||||
|
|
||||||
function M.set_index_and_redraw(fname)
|
function M.set_index_and_redraw(fname)
|
||||||
local i
|
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
|
i = 0
|
||||||
else
|
else
|
||||||
i = 1
|
i = 1
|
||||||
|
|||||||
@ -266,7 +266,9 @@ local function update_draw_data(tree, depth, markers)
|
|||||||
["readme.md"] = true,
|
["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({
|
local root_name = utils.path_join({
|
||||||
utils.path_remove_trailing(vim.fn.fnamemodify(tree.cwd, root_folder_modifier)),
|
utils.path_remove_trailing(vim.fn.fnamemodify(tree.cwd, root_folder_modifier)),
|
||||||
".."
|
".."
|
||||||
|
|||||||
@ -9,6 +9,7 @@ end
|
|||||||
M.View = {
|
M.View = {
|
||||||
bufnr = nil,
|
bufnr = nil,
|
||||||
tabpages = {},
|
tabpages = {},
|
||||||
|
hide_root_folder = false,
|
||||||
winopts = {
|
winopts = {
|
||||||
relativenumber = false,
|
relativenumber = false,
|
||||||
number = false,
|
number = false,
|
||||||
@ -144,6 +145,7 @@ function M.setup(opts)
|
|||||||
M.View.side = options.side
|
M.View.side = options.side
|
||||||
M.View.width = options.width
|
M.View.width = options.width
|
||||||
M.View.height = options.height
|
M.View.height = options.height
|
||||||
|
M.View.hide_root_folder = options.hide_root_folder
|
||||||
M.View.auto_resize = opts.auto_resize
|
M.View.auto_resize = opts.auto_resize
|
||||||
if options.mappings.custom_only then
|
if options.mappings.custom_only then
|
||||||
M.View.mappings = options.mappings.list
|
M.View.mappings = options.mappings.list
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user