commit 344119439e417839d217f31c6195f996e91ce8a1
parent 90d08dc626f0638cd079895a68ee0cf7f7e03d9a
Author: Jason Franklin <j_fra@fastmail.us>
Date: Thu, 21 Dec 2017 10:26:07 -0500
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.
Diffstat:
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git 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
@@ -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())