From 84a4abb902a170d557ea9b62a74abe029bc84ed4 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 17 Oct 2022 12:54:31 +1100 Subject: [PATCH] fix(#1664): respect hijack_directories.enable on startup when not open_on_setup --- doc/nvim-tree-lua.txt | 3 ++- lua/nvim-tree.lua | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index fbf810f0ca5..58d8a45890e 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -491,7 +491,8 @@ Will change cwd of nvim-tree to that of new buffer's when opening nvim-tree. Type: `boolean`, Default: `false` *nvim-tree.hijack_directories* (previously `update_to_buf_dir`) -hijacks new directory buffers when they are opened (`:e dir`). +hijacks new directory buffers when they are opened (`:e dir`) or if a +directory is opened on startup e.g. `nvim .` *nvim-tree.hijack_directories.enable* Enable the feature. diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 6e192419e85..47b186224fd 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -257,13 +257,18 @@ function M.on_enter(netrw_disabled) end end + local should_hijack = _config.hijack_directories.enable + and _config.hijack_directories.auto_open + and is_dir + and not should_be_preserved + -- Session that left a NvimTree Buffer opened, reopen with it local existing_tree_wins = find_existing_windows() if existing_tree_wins[1] then api.nvim_set_current_win(existing_tree_wins[1]) end - if should_open or existing_tree_wins[1] ~= nil then + if should_open or should_hijack or existing_tree_wins[1] ~= nil then lib.open(cwd) if should_focus_other_window then