Verify we haven't reached root when traversing cascade

This commit is contained in:
Łukasz Adamczak
2016-06-22 13:59:49 +02:00
parent c99312442b
commit 2924ab2071

View File

@@ -187,10 +187,7 @@ endfunction
" closes the parent dir of the current node " closes the parent dir of the current node
function! s:closeCurrentDir(node) function! s:closeCurrentDir(node)
let parent = a:node.parent let parent = a:node.parent
if parent ==# {} || parent.isRoot() while g:NERDTreeCascadeOpenSingleChildDir && !parent.isRoot()
call nerdtree#echo("cannot close tree root")
else
while g:NERDTreeCascadeOpenSingleChildDir && !parent.parent.isRoot()
let childNodes = parent.getVisibleChildren() let childNodes = parent.getVisibleChildren()
if len(childNodes) == 1 && childNodes[0].path.isDirectory if len(childNodes) == 1 && childNodes[0].path.isDirectory
let parent = parent.parent let parent = parent.parent
@@ -198,6 +195,9 @@ function! s:closeCurrentDir(node)
break break
endif endif
endwhile endwhile
if parent ==# {} || parent.isRoot()
call nerdtree#echo("cannot close tree root")
else
call parent.close() call parent.close()
call b:NERDTree.render() call b:NERDTree.render()
call parent.putCursorHere(0, 0) call parent.putCursorHere(0, 0)