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.
This commit is contained in:
Jason Franklin 2017-12-21 10:26:07 -05:00
parent 90d08dc626
commit 344119439e
2 changed files with 7 additions and 5 deletions

View File

@ -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)

View File

@ -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())