From c99312442b0961241eb0de3d6d65893c52f4d9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Adamczak?= Date: Wed, 22 Jun 2016 13:32:44 +0200 Subject: [PATCH 1/2] Fix upward traversal when closing a cascade --- autoload/nerdtree/ui_glue.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 0912faf..4cbfb38 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -191,8 +191,8 @@ function! s:closeCurrentDir(node) call nerdtree#echo("cannot close tree root") else while g:NERDTreeCascadeOpenSingleChildDir && !parent.parent.isRoot() - if parent.parent.getVisibleChildCount() == 1 - call parent.close() + let childNodes = parent.getVisibleChildren() + if len(childNodes) == 1 && childNodes[0].path.isDirectory let parent = parent.parent else break From 2924ab207162ca18cf5844d00b351ade1b5122f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Adamczak?= Date: Wed, 22 Jun 2016 13:59:49 +0200 Subject: [PATCH 2/2] Verify we haven't reached root when traversing cascade --- autoload/nerdtree/ui_glue.vim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 4cbfb38..2aa3bec 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -187,17 +187,17 @@ endfunction " closes the parent dir of the current node function! s:closeCurrentDir(node) let parent = a:node.parent + while g:NERDTreeCascadeOpenSingleChildDir && !parent.isRoot() + let childNodes = parent.getVisibleChildren() + if len(childNodes) == 1 && childNodes[0].path.isDirectory + let parent = parent.parent + else + break + endif + endwhile if parent ==# {} || parent.isRoot() call nerdtree#echo("cannot close tree root") else - while g:NERDTreeCascadeOpenSingleChildDir && !parent.parent.isRoot() - let childNodes = parent.getVisibleChildren() - if len(childNodes) == 1 && childNodes[0].path.isDirectory - let parent = parent.parent - else - break - endif - endwhile call parent.close() call b:NERDTree.render() call parent.putCursorHere(0, 0)