From 344119439e417839d217f31c6195f996e91ce8a1 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Thu, 21 Dec 2017 10:26:07 -0500 Subject: [PATCH] Refresh children of directory nodes on "reveal()" The ":NERDTreeFind" command calls the "reveal()" method on the NERDTree root node. The "reveal()" method would, in turn, call the node's "open()" method. Since the "open()" method would only initialize the child nodes of the root (i.e., read them from disk) when the list of child nodes was empty, new paths would not be included in the list. This commit will result in the refreshing of the child node list whenever "reveal()" is called on a directory node (unless it is the first time the node is being opened... the most efficient option). The result is that ":NERDTreeFind" will discover newly created paths that exist on disk but are not cached in the NERDTree. A stray debugging message is also removed. Fixes issue #779. --- autoload/nerdtree/ui_glue.vim | 5 ----- lib/nerdtree/tree_dir_node.vim | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 894a88a..910ead3 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -304,11 +304,6 @@ function! s:findAndRevealPath(path) endif let l:node = b:NERDTree.root.reveal(l:pathObj) - - if empty(l:node) - echomsg 'l:node is totally empty...' - endif - call b:NERDTree.render() call l:node.putCursorHere(1, 0) diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim index 03c3545..43285db 100644 --- a/lib/nerdtree/tree_dir_node.vim +++ b/lib/nerdtree/tree_dir_node.vim @@ -568,6 +568,13 @@ function! s:TreeDirNode.reveal(path, ...) throw "NERDTree.InvalidArgumentsError: " . a:path.str() . " should be under " . self.path.str() endif + " Refresh "self.children" to avoid missing paths created after this node + " was last opened. If "self.children" is empty, the call to "open()" will + " initialize the children. + if !empty(self.children) + " Silence messages/errors. They were seen on the first open. + silent! call self._initChildren(1) + endif call self.open() if self.path.equals(a:path.getParent())