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
6 changed files with 18 additions and 4 deletions

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