commit 0b966aa23a8d786414a07eafbef3572bd44c30ea
parent 449f2c77ed5e6b921b29c60351a3efc6b58bfdb0
Author: Martin Grenfell <martin.grenfell@gmail.com>
Date: Mon, 16 Nov 2015 09:35:31 +0000
refactor TreeDirNode.reveal slightly
Diffstat:
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim
@@ -289,7 +289,9 @@ function! s:findAndRevealPath()
endif
endif
call g:NERDTree.CursorToTreeWin()
- call b:NERDTreeRoot.reveal(p)
+ let node = b:NERDTreeRoot.reveal(p)
+ call b:NERDTree.render()
+ call node.putCursorHere(1,0)
if p.isUnixHiddenFile()
let g:NERDTreeShowHidden = showhidden
diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim
@@ -460,7 +460,10 @@ endfunction
"FUNCTION: TreeDirNode.reveal(path) {{{1
"reveal the given path, i.e. cache and open all treenodes needed to display it
"in the UI
-function! s:TreeDirNode.reveal(path)
+"Returns the revealed node
+function! s:TreeDirNode.reveal(path, ...)
+ let opts = a:0 ? a:1 : {}
+
if !a:path.isUnder(self.path)
throw "NERDTree.InvalidArgumentsError: " . a:path.str() . " should be under " . self.path.str()
endif
@@ -469,9 +472,10 @@ function! s:TreeDirNode.reveal(path)
if self.path.equals(a:path.getParent())
let n = self.findNode(a:path)
- call b:NERDTree.render()
- call n.putCursorHere(1,0)
- return
+ if has_key(opts, "open")
+ call n.open()
+ endif
+ return n
endif
let p = a:path
@@ -480,7 +484,7 @@ function! s:TreeDirNode.reveal(path)
endwhile
let n = self.findNode(p)
- call n.reveal(a:path)
+ return n.reveal(a:path, opts)
endfunction
"FUNCTION: TreeDirNode.removeChild(treenode) {{{1