Skip to content

Commit

Permalink
Merge pull request #801 from mrubli/focus-on-close
Browse files Browse the repository at this point in the history
Fix focussing previous buffer when closing NERDTree
  • Loading branch information
PhilRunninger authored Feb 2, 2018
2 parents 68572ef + a0f3bf3 commit e47e588
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/nerdtree/nerdtree.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,26 @@ function! s:NERDTree.Close()
endif

if winnr("$") != 1
" Use the window ID to identify the currently active window or fall
" back on the buffer ID if win_getid/win_gotoid are not available, in
" which case we'll focus an arbitrary window showing the buffer.
let l:useWinId = exists('*win_getid') && exists('*win_gotoid')

if winnr() == s:NERDTree.GetWinNum()
call nerdtree#exec("wincmd p")
let bufnr = bufnr("")
let l:activeBufOrWin = l:useWinId ? win_getid() : bufnr("")
call nerdtree#exec("wincmd p")
else
let bufnr = bufnr("")
let l:activeBufOrWin = l:useWinId ? win_getid() : bufnr("")
endif

call nerdtree#exec(s:NERDTree.GetWinNum() . " wincmd w")
close
call nerdtree#exec(bufwinnr(bufnr) . " wincmd w")
if l:useWinId
call nerdtree#exec("call win_gotoid(" . l:activeBufOrWin . ")")
else
call nerdtree#exec(bufwinnr(l:activeBufOrWin) . " wincmd w")
endif
else
close
endif
Expand Down

0 comments on commit e47e588

Please sign in to comment.