From 859be0bb76b87f7f7fdeb7da7031d19ce612bb5c Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Mon, 3 Aug 2020 20:51:01 +0200 Subject: [PATCH] Merge root folder and parent navigator into one. --- doc/nvim-tree-lua.txt | 2 +- lua/lib/lib.lua | 6 +++--- lua/lib/renderer.lua | 10 ++-------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index dacb5942..c9db0bff 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -146,7 +146,7 @@ Can be `0` or `1`. When `1`, will hide dotfiles, files or folders which start with the `.` character. Default is 0 -|g:lua_tree_root_folder_modifier| *g:lua_tree_hide_dotfiles* +|g:lua_tree_root_folder_modifier| *g:lua_tree_root_folder_modifier* In what format to show root folder. See `:help filename-modifiers` for available options. diff --git a/lua/lib/lib.lua b/lua/lib/lib.lua index eafd0afb..04a277fd 100644 --- a/lua/lib/lib.lua +++ b/lua/lib/lib.lua @@ -58,7 +58,7 @@ function M.init(with_open, with_render) end local function get_node_at_line(line) - local index = 3 + local index = 2 local function iter(entries) for _, node in ipairs(entries) do if index == line then @@ -135,9 +135,9 @@ end function M.set_index_and_redraw(fname) local i if M.Tree.cwd == '/' then - i = 1 + i = 0 else - i = 2 + i = 1 end local reload = false diff --git a/lua/lib/renderer.lua b/lua/lib/renderer.lua index 0bb5a60d..24e3045a 100644 --- a/lua/lib/renderer.lua +++ b/lua/lib/renderer.lua @@ -164,16 +164,10 @@ local root_folder_modifier = vim.g.lua_tree_root_folder_modifier or ':~' local function update_draw_data(tree, depth, markers) if tree.cwd and tree.cwd ~= '/' then - table.insert(lines, ".. (up a dir)") - table.insert(hl, {'LuaTreeFolderName', index, 0, 13}) - index = 1 - end - - if tree.cwd then - local root_name = vim.fn.fnamemodify(tree.cwd, root_folder_modifier) + local root_name = vim.fn.fnamemodify(tree.cwd, root_folder_modifier):gsub('/$', '').."/.." table.insert(lines, root_name) table.insert(hl, {'LuaTreeRootFolder', index, 0, string.len(root_name)}) - index = tree.cwd ~= '/' and 2 or 1 + index = 1 end for idx, node in ipairs(tree.entries) do