Closed
Description
Description
Background - I have the following options enabled:
sync_root_with_cwd = true
update_focused_file = { enable = true, update_root = true, ignore_list = {'help'} }
Scenario:
- I have a single tab with 1 file open, where the window
lcd
is set to a certain directory. - I open another window with
:new
and open a file in a different directory. - I use :NvimTreeToggle to open nvim-tree and see that the root is set to the correct directory of the file that I just opened.
- Within the window of the new file, I
:lcd ..
to one level up. Again, nvim-tree is updated properly. - If I then close and reopen nvim-tree two times with :NvimTreeToggle, then the root is updated to the direct parent directory of the file, which seems to contradict the intended behavior of
Update_focused_file.update_root
.
This does not happen when changing focus between two windows. The root of nvim-tree is properly updated without resetting directly to the parent directory of the second file. Also, it seems like it has to be the bottom window in the layout for it to reset. It doesn't happen with the top one.
Neovim version
NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@HMBRW-A-001-M1-004.local
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.7.2_1/share/nvim"
Run :checkhealth for more info
Operating system and version
macOS 12.5
nvim-tree version
Minimal config
vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvt-min/site]]
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
require("packer").startup {
{
"wbthomason/packer.nvim",
"kyazdani42/nvim-tree.lua",
"kyazdani42/nvim-web-devicons",
-- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
},
config = {
package_root = package_root,
compile_path = install_path .. "/plugin/packer_compiled.lua",
display = { non_interactive = true },
},
}
end
if vim.fn.isdirectory(install_path) == 0 then
print "Installing nvim-tree and dependencies."
vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
end
load_plugins()
require("packer").sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true
-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
require("nvim-tree").setup {
sync_root_with_cwd = true,
update_focused_file = {
enable = true,
update_root = true,
ignore_list = {'help'}
}
}
end
Steps to reproduce
- Open a file in Nvim.
- Do
:new
- Open a file in a different directory in the second window.
- Do
:lcd ..
- Execute
:NvimTreeToggle
twice. - See the root of nvim-tree reset to the parent of the lower file.
Expected behavior
The root should not reset to the parent directory because according to the description of update_focused_file.update_root
, It should only Update the root directory of the tree if the file is not under current root directory.
Actual behavior
After toggling nvim-tree a few times, the root is updated to the containing directory of the file.