diff --git a/README.md b/README.md index 5c1196cb..1c3857e2 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ let g:lua_tree_indent_markers = 1 "0 by default, this option shows indent marker let g:lua_tree_hide_dotfiles = 1 "0 by default, this option hides files and folders starting with a dot `.` let g:lua_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons). let g:lua_tree_root_folder_modifier = ':~' "This is the default. See :help filename-modifiers for more options +let g:lua_tree_tab_open = 1 "0 by default, will open the tree when entering a new tab and the tree was previously open let g:lua_tree_show_icons = { \ 'git': 1, \ 'folders': 0, diff --git a/doc/.gitignore b/doc/.gitignore new file mode 100644 index 00000000..6e92f57d --- /dev/null +++ b/doc/.gitignore @@ -0,0 +1 @@ +tags diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 48501ae1..41e669f3 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -157,6 +157,12 @@ In what format to show root folder. See `:help filename-modifiers` for available options. Default is `:~` +|g:lua_tree_tab_open| *g:lua_tree_tab_open* + +Can be 0 or 1. When 1, will open the tree when entering a new tab if the +tree was previously open. +Default is 0 + ============================================================================== INFORMATIONS *nvim-tree-info* diff --git a/doc/tags b/doc/tags deleted file mode 100644 index dff2d3df..00000000 --- a/doc/tags +++ /dev/null @@ -1,29 +0,0 @@ -:LuaTreeClipboard nvim-tree-lua.txt /*:LuaTreeClipboard* -:LuaTreeClose nvim-tree-lua.txt /*:LuaTreeClose* -:LuaTreeFindFile nvim-tree-lua.txt /*:LuaTreeFindFile* -:LuaTreeOpen nvim-tree-lua.txt /*:LuaTreeOpen* -:LuaTreeRefresh nvim-tree-lua.txt /*:LuaTreeRefresh* -:LuaTreeToggle nvim-tree-lua.txt /*:LuaTreeToggle* -g:lua_tree_auto_close nvim-tree-lua.txt /*g:lua_tree_auto_close* -g:lua_tree_auto_open nvim-tree-lua.txt /*g:lua_tree_auto_open* -g:lua_tree_bindings nvim-tree-lua.txt /*g:lua_tree_bindings* -g:lua_tree_disable_keybindings nvim-tree-lua.txt /*g:lua_tree_disable_keybindings* -g:lua_tree_follow nvim-tree-lua.txt /*g:lua_tree_follow* -g:lua_tree_git_hl nvim-tree-lua.txt /*g:lua_tree_git_hl* -g:lua_tree_icons nvim-tree-lua.txt /*g:lua_tree_icons* -g:lua_tree_ignore nvim-tree-lua.txt /*g:lua_tree_ignore* -g:lua_tree_indent_markers nvim-tree-lua.txt /*g:lua_tree_indent_markers* -g:lua_tree_show_icons nvim-tree-lua.txt /*g:lua_tree_show_icons* -g:lua_tree_hide_dotfiles nvim-tree-lua.txt /*g:lua_tree_hide_dotfiles* -g:lua_tree_side nvim-tree-lua.txt /*g:lua_tree_side* -g:lua_tree_size nvim-tree-lua.txt /*g:lua_tree_size* -lua_tree_highlight nvim-tree-lua.txt /*lua_tree_highlight* -nvim-tree-commands nvim-tree-lua.txt /*nvim-tree-commands* -nvim-tree-features nvim-tree-lua.txt /*nvim-tree-features* -nvim-tree-highlight nvim-tree-lua.txt /*nvim-tree-highlight* -nvim-tree-info nvim-tree-lua.txt /*nvim-tree-info* -nvim-tree-introduction nvim-tree-lua.txt /*nvim-tree-introduction* -nvim-tree-keybindings nvim-tree-lua.txt /*nvim-tree-keybindings* -nvim-tree-options nvim-tree-lua.txt /*nvim-tree-options* -nvim-tree-quickstart nvim-tree-lua.txt /*nvim-tree-quickstart* -nvim-tree.lua nvim-tree-lua.txt /*nvim-tree.lua* diff --git a/lua/tree.lua b/lua/tree.lua index effe8a92..f2bb12dc 100644 --- a/lua/tree.lua +++ b/lua/tree.lua @@ -24,6 +24,7 @@ end function M.close() if lib.win_open() then lib.close() + return true end end @@ -33,6 +34,17 @@ function M.open() end end +local winopts = config.window_options() +function M.tab_change() + -- we need defer_fn to make sure we close/open after we enter the tab + vim.defer_fn(function() + if M.close() then + M.open() + api.nvim_command('wincmd '..winopts.open_command) + end + end, 1) +end + local function gen_go_to(mode) local icon_state = config.get_icon_state() local flags = mode == 'prev_git_item' and 'b' or '' diff --git a/plugin/tree.vim b/plugin/tree.vim index 0f8f1527..4935bb9a 100644 --- a/plugin/tree.vim +++ b/plugin/tree.vim @@ -17,6 +17,9 @@ augroup LuaTree au VimEnter * lua require'tree'.on_enter() au ColorScheme * lua require'tree'.reset_highlight() au User FugitiveChanged lua require'tree'.refresh() + if get(g:, 'lua_tree_tab_open') == 1 + au TabEnter * lua require'tree'.tab_change() + endif augroup end command! LuaTreeOpen lua require'tree'.open()