Merge pull request #878 from scrooloose/autochdir_interference

NERDTreeCWD: reset CWD if changed by NERDTreeFocus
This commit is contained in:
Phil Runninger 2018-09-10 09:27:52 -04:00 committed by GitHub
commit 15d06b676d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 16 deletions

View File

@ -142,18 +142,9 @@ function! s:chRoot(node)
endfunction
" FUNCTION: s:nerdtree#ui_glue#chRootCwd() {{{1
" changes the current root to CWD
" Change the NERDTree root to match the current working directory.
function! nerdtree#ui_glue#chRootCwd()
try
let cwd = g:NERDTreePath.New(getcwd())
catch /^NERDTree.InvalidArgumentsError/
call nerdtree#echo("current directory does not exist.")
return
endtry
if cwd.str() == g:NERDTreeFileNode.GetRootForTab().path.str()
return
endif
call s:chRoot(g:NERDTreeDirNode.New(cwd, b:NERDTree))
NERDTreeCWD
endfunction
" FUNCTION: nnerdtree#ui_glue#clearBookmarks(bookmarks) {{{1

View File

@ -142,8 +142,8 @@ The following features and functionality are provided by the NERD tree:
current tab does not exist, a new one will be initialized.
:NERDTreeCWD *:NERDTreeCWD*
Change tree root to current directory. If no NERD tree exists for this
tab, a new tree will be opened.
Change the NERDTree root to the current working directory. If no
NERDTree exists for this tab, a new one is opened.
------------------------------------------------------------------------------
2.2. Bookmarks *NERDTreeBookmarks*
@ -522,7 +522,7 @@ Default key: cd
Map option: NERDTreeMapChdir
Applies to: files and directories.
Change vims current working directory to that of the selected node.
Change Vim's current working directory to that of the selected node.
------------------------------------------------------------------------------
*NERDTree-CD*
@ -530,7 +530,7 @@ Default key: CD
Map option: NERDTreeMapCWD
Applies to: no restrictions.
Change tree root to vims current working directory.
Change the NERDTree root to Vim's current working directory.
------------------------------------------------------------------------------
*NERDTree-I*

View File

@ -202,8 +202,28 @@ function! NERDTreeFocus()
endfunction
function! NERDTreeCWD()
if empty(getcwd())
call nerdtree#echoWarning('current directory does not exist')
return
endif
try
let l:cwdPath = g:NERDTreePath.New(getcwd())
catch /^NERDTree.InvalidArgumentsError/
call nerdtree#echoWarning('current directory does not exist')
return
endtry
call NERDTreeFocus()
call nerdtree#ui_glue#chRootCwd()
if b:NERDTree.root.path.equals(l:cwdPath)
return
endif
let l:newRoot = g:NERDTreeFileNode.New(l:cwdPath, b:NERDTree)
call b:NERDTree.changeRoot(l:newRoot)
normal! ^
endfunction
function! NERDTreeAddPathFilter(callback)