-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NERDTree jumps to open file on write #983
Comments
I'm having this issue too: OS: NerdTree related configuration:
|
Can either of you give me a clearer set of steps to reproduce this? I see that @nickolashkraus is using |
To me, this issue occurs when there's any open floating window (I'm using Coc.nvim) as seen here: After debugging to find which setting was responsible, I found that setting I also raised an issue in chat with |
@nickolashkraus @hbarcelos @codingedward autocmd CursorHold
autocmd CursorHoldI
autocmd CursorMoved
autocmd CursorMovedI
autocmd BufEnter
autocmd BufLeave
autocmd WinEnter
autocmd WinLeave I'm sure this is only the first step in tracking this down. Thanks for your help. |
Here's what I got:
|
@hbarcelos @codingedward are you using |
Hi @nickolashkraus About the commands you asked for: `autocmd CursorHold`:
`autocmd CursorHoldI`:``` signify CursorHoldI * call sy#start() ````autocmd CursorMoved`:``` ALEEvents CursorMoved * if exists('*ale#engine#Cleanup') | call ale#cursor#EchoCursorWarningWithDelay() | endif lightline CursorMoved * call lightline#update_once() matchparen CursorMoved * call s:Highlight_Matching_Pair() ycmcompletemecursormove CursorMoved * call s:OnCursorMovedNormalMode() startify CursorMoved call s:set_cursor() ContextCommentstringEnabled CursorMoved call UpdateCommentString() ````autocmd CursorMovedI`:``` matchparen CursorMovedI * call s:Highlight_Matching_Pair() better_whitespace CursorMovedI * call HighlightEOLWhitespaceExceptCurrentLine() call HighlightEOLWhitespaceExceptCurrentLine() ````autocmd BufEnter`:
`autocmd BufLeave`:``` NERDTree BufLeave NERD_tree_* if g:NERDTree.IsOpen() | call b:NERDTree.ui.saveScreenState() | endif ````autocmd WinEnter`:``` WinEnter * call SetupAutoCommands() lightline WinEnter * call lightline#update() signify WinEnter * call sy#start() NERDTree WinEnter NERD_tree_* stopinsert tmux_navigator WinEnter * let s:tmux_is_last_pane = 0 matchparen WinEnter * call s:Highlight_Matching_Pair() youcompleteme WinEnter * call s:UpdateMatches() ````autocmd WinLeave`:
|
Yes @nickolashkraus I'm using it. |
I have tried disabling it (by commenting out the |
Alright, I have a down day so I am going to dig into this issue. I have had problems with nerdtree-git-plugin in the past, since it hijacks NERDTree's functions. |
@codingedward You may need to run |
I was able to reliably reproduce the issue. After removing nerdtree-git-plugin, NERDTree no longer jumped to the open file on write. Looking into why this is the case. I like nerdtree-git-plugin, however it is buggy as hell and the maintainer is unresponsive. |
Hello @nickolashkraus, I removed I'll also do a bit of debugging on my side and see if I can provide a minimal |
Hello @nickolashkraus, @PhilRunninger. After a bit of debugging, I can confirm that the culprit is Interestingly, since I use another NERDTree plugin vim-devicons, disabling It turns out that these two plugins share a chunk of code that is responsible for the malfunction: In " FUNCTION: s:CursorHoldUpdate() {{{2
function! s:CursorHoldUpdate()
if g:NERDTreeUpdateOnCursorHold != 1
return
endif
if !g:NERDTree.IsOpen()
return
endif
" Do not update when a special buffer is selected
if !empty(&l:buftype)
return
endif
let l:winnr = winnr()
let l:altwinnr = winnr('#')
call g:NERDTree.CursorToTreeWin() " <-------- the offending call
call b:NERDTree.root.refreshFlags()
call NERDTreeRender()
exec l:altwinnr . 'wincmd w'
exec l:winnr . 'wincmd w'
endfunction and in " scope: local
" stole solution/idea from nerdtree-git-plugin :)
function! s:CursorHoldUpdate()
if g:NERDTreeUpdateOnCursorHold != 1
return
endif
if !exists('g:NERDTree') || !g:NERDTree.IsOpen()
return
endif
" Do not update when a special buffer is selected
if !empty(&l:buftype)
return
endif
" winnr need to make focus go to opened file
" CursorToTreeWin needed to avoid error on opening file
let l:winnr = winnr()
let l:altwinnr = winnr('#')
call g:NERDTree.CursorToTreeWin() " <-------- the offending call
call b:NERDTree.root.refreshFlags()
call NERDTreeRender()
exec l:altwinnr . 'wincmd w'
exec l:winnr . 'wincmd w'
endfunction The function causing the issues is the call to Instead of this, I am guessing both authors ought to have called |
Excellent sleuthing @codingedward. Even if you don't submit PR's to fix them, raising issues on both the other repositories and linking them back here is probably the best first step to getting fixes landed in the right places. |
@nickolashkraus @codingedward Thanks for digging into the code, while I currently cannot spare the time to do so. Regarding your proposed solution, I'm not sure it's that simple, because function! NERDTreeFocus()
if g:NERDTree.IsOpen()
call g:NERDTree.CursorToTreeWin()
else
call g:NERDTreeCreator.ToggleTabTree('')
endif
endfunction function! s:NERDTree.CursorToTreeWin()
call g:NERDTree.MustBeOpen()
call nerdtree#exec(g:NERDTree.GetWinNum() . 'wincmd w', 1)
endfunction
function! s:NERDTree.MustBeOpen()
if !s:NERDTree.IsOpen()
throw 'NERDTree.TreeNotOpen'
endif
endfunction |
Agreed. I don't think it is function! NERDTreeRender()
call nerdtree#renderView()
endfunction "FUNCTION: nerdtree#renderView {{{2
function! nerdtree#renderView()
call b:NERDTree.render()
endfunction " FUNCTION: s:UI.render() {{{1
function! s:UI.render()
setlocal noreadonly modifiable
" remember the top line of the buffer and the current line so we can
" restore the view exactly how it was
let curLine = line(".")
let curCol = col(".")
let topLine = line("w0")
" delete all lines in the buffer (being careful not to clobber a register)
silent 1,$delete _
call self._dumpHelp()
" delete the blank line before the help and add one after it
if !self.isMinimal()
call setline(line(".")+1, "")
call cursor(line(".")+1, col("."))
endif
if self.getShowBookmarks()
call self._renderBookmarks()
endif
" add the 'up a dir' line
if !self.isMinimal()
call setline(line(".")+1, s:UI.UpDirLine())
call cursor(line(".")+1, col("."))
endif
" draw the header line
let header = self.nerdtree.root.path.str({'format': 'UI', 'truncateTo': winwidth(0)})
call setline(line(".")+1, header)
call cursor(line(".")+1, col("."))
" draw the tree
silent put =self.nerdtree.root.renderToString()
" delete the blank line at the top of the buffer
silent 1,1delete _
" restore the view
let old_scrolloff=&scrolloff
let &scrolloff=0
call cursor(topLine, 1)
normal! zt
call cursor(curLine, curCol)
let &scrolloff = old_scrolloff
setlocal readonly nomodifiable
endfunction Of interest are the last few lines: " restore the view
let old_scrolloff=&scrolloff
let &scrolloff=0
call cursor(topLine, 1)
normal! zt
call cursor(curLine, curCol)
let &scrolloff = old_scrolloff This is responsible for returning the view by repositioning the edit window. |
This only occurs however when the window height is sufficiently small (execute |
Steps to repro for me are:
|
I can confirm that disabling the call to Interestingly, also calling |
|
|
My bad, I was using Disabling I could raise issues on the two plugins ( |
Disabling |
I'd be more inclined to find a root cause and a solution in NERDTreeRender. These and other plugins need to know that's a safe function to call after their Listener functions do their thing. |
@hbarcelos @codingedward can you provide the output of |
Hello @nickolashkraus, Here's what I got:
|
There you go:
Sorry not being able to help with the debugging process, it's been some pretty busy days for me 😞 |
I just merged a pull request that addresses three other issues. Given it also was related to autocommands, it may fix this one too. No guarantees though. Give it a shot with the latest master, and let us know. |
@PhilRunninger, I have updated my NERDTree plugin and I can confirm that the issue persists. |
For what it's worth, I am (still) having the same issue, with up-to-date |
My nerdtree is "scrolling" each time when I invoke my ctrlP plugin. After ctrlP dialog is closed nerdtree content is not coming back down and I need to adjust it manuallly. Let me know if I can help with debugging somehow. |
@codingedward have you found a solution to this problem? I also use |
Yep, sad problem :( No workaround? |
Environment
:version
: VIM - Vi IMproved 8.1 macOS versiongit rev-parse --short HEAD
:f4d2b30
Process
vim
.:w
).Current Result
NERDTree navigation moves to current file (see GIF).
Expected Result
NERDTree does not move.
Screenshot(s)
Possible Fix
Not sure..
Updates
01.09.2020
Bug occurs when opening a location list, not a quickfix list.
The text was updated successfully, but these errors were encountered: