feat: add hide_root_folder (#728)

This commit is contained in:
M.A 2021-10-24 17:48:57 +03:00 committed by GitHub
parent 6cadd3a9d7
commit fd3969ec98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 4 deletions

View File

@ -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

View File

@ -230,6 +230,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`

View File

@ -415,6 +415,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,

View File

@ -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
@ -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
@ -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
@ -202,7 +203,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

View File

@ -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)),
".."

View File

@ -9,6 +9,7 @@ end
M.View = {
bufnr = nil,
tabpages = {},
hide_root_folder = false,
winopts = {
relativenumber = false,
number = false,
@ -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