Nvimtree unexpectedly changes root directory on focus to itself
alfa07 opened this issue · comments
OS
Distributor ID: Ubuntu
Description: Datadog Ubuntu Preseed 20.04 v14 customized using Cubic on 2021-09-13 09:52
Release: 20.04
Codename: focal
Neovim version
NVIM v0.6.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by linuxbrew@47b333addab8
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "
/home/linuxbrew/.linuxbrew/Cellar/neovim/0.6.0/share/nvim"
Run :checkhealth for more info
Nvim-tree version
❯ git status
HEAD detached at f408781
Describe the bug
When keyboard focus moves to Nvimtree it unexpectedly changes root directory.
To Reproduce
Steps to reproduce:
- Open file AF in repo A
- Show nvimtree with
<space>e
- Open file BF in repo B
- Observe that nvimtree shows file BF and rooted at repo B
- Hit
<C-h>
to get into nvimtree panel - BUG: nvimtree changes root to repo A
- Expected behavior nvimtree should stay at repo B
What is happening is that (most likely) this event gets fired when cursor moves to nvimtree buffer:
https://github.com/kyazdani42/nvim-tree.lua/blob/65b8b19c8bcea36e37474338c7e2d2fea95553d3/lua/nvim-tree.lua#L399
which for whatever reason has vim.loop.cwd()
set to directory which does not match root which is currently displayed.
The workaround is to add this to config.vim:
local nvimtree_lib = require "nvim-tree.lib"
local change_dir = nvimtree_lib.change_dir
local is_file = require "project_nvim.project".is_file
nvimtree_lib.change_dir = function(d)
if not is_file() then
return
end
change_dir(d)
end
Expected behavior
Nvimtree should not change directory when focus moves to itself or other non-file buffers.
See also LunarVim/LunarVim#2106
Hi !
i've noticed this annoying behavior too, i'll fix this