Skip to content
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

NERDTreeCWD: reset CWD if changed by NERDTreeFocus #878

Merged
merged 6 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions autoload/nerdtree/ui_glue.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions doc/NERDTree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down Expand Up @@ -522,15 +522,15 @@ 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*
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*
Expand Down
22 changes: 21 additions & 1 deletion plugin/NERD_tree.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down