From 3da6a02eb8b19c7ac2bbee764c0849442783096b Mon Sep 17 00:00:00 2001 From: Julius Zint Date: Sat, 16 Jul 2022 12:40:04 +0200 Subject: [PATCH] [Fix] closing of collapsible directories in NERDTree plugin The NERDTree plugin will under some conditions fail to close a collapisble directory with the error message: "cannot close tree root". This commit replaces the traversing logic for collapsible directories when closing with the latest code from NERDTree. To reproduce this error use 'g:NERDTreeCascadeSingleChildDir=0' and 'g:NERDTreeCascadeOpenSingleChildDir=1'. Then the following dir tree: dir-a dir-b dir-c dir-d Go over dir-c and press "x" to close this node. --- nerdtree_plugin/webdevicons.vim | 38 +++++++++++++++------------------ 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/nerdtree_plugin/webdevicons.vim b/nerdtree_plugin/webdevicons.vim index 7c1f9f7..a582305 100644 --- a/nerdtree_plugin/webdevicons.vim +++ b/nerdtree_plugin/webdevicons.vim @@ -257,28 +257,24 @@ function! WebDevIconsNERDTreeMapCloseChildren(node) endfunction function! WebDevIconsNERDTreeMapCloseDir(node) - " continue with normal original logic: - 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 + let l:parent = a:node.parent + while l:parent.isCascadable() + let l:parent = l:parent.parent endwhile - if parent ==# {} || parent.isRoot() - call nerdtree#echo('cannot close tree root') - else - call parent.close() - " update the glyph - call WebDevIconsNERDTreeDirClose(parent) - call b:NERDTree.render() - call parent.putCursorHere(0, 0) - " glyph change possible artifact clean-up - if g:DevIconsEnableNERDTreeRedraw ==# 1 - redraw! - endif + + if l:parent.isRoot() + call nerdtree#echo('cannot close tree root') + return + endif + + call parent.close() + " update the glyph + call WebDevIconsNERDTreeDirClose(parent) + call b:NERDTree.render() + call parent.putCursorHere(0, 0) + " glyph change possible artifact clean-up + if g:DevIconsEnableNERDTreeRedraw ==# 1 + redraw! endif endfunction