Merge pull request #720 from lifecrisis/issue526

BUGFIX: Repair opening and closing of cascades.
This commit is contained in:
Jason Franklin 2017-07-08 10:04:08 -04:00 committed by GitHub
commit ab0a3a7c24
3 changed files with 64 additions and 54 deletions

View File

@ -59,7 +59,7 @@ Installation
git clone https://github.com/scrooloose/nerdtree.git ~/.vim/bundle/nerdtree
Then reload vim, run `:helptags ~/.vim/bundle/nerdtree/doc/`, and check out `:help NERD_tree.txt`.
Then reload Vim, run `:helptags ~/.vim/bundle/nerdtree/doc/`, and check out `:help NERDTree.txt`.
#### [apt-vim](https://github.com/egalpin/apt-vim)

View File

@ -1,4 +1,4 @@
*NERD_tree.txt* A tree explorer plugin that owns your momma!
*NERDTree.txt* A tree explorer plugin that owns your momma!

View File

@ -45,9 +45,14 @@ function! s:TreeDirNode.addChild(treenode, inOrder)
endfunction
" FUNCTION: TreeDirNode.close() {{{1
" Closes this directory
" Mark this TreeDirNode as closed.
function! s:TreeDirNode.close()
let self.isOpen = 0
" Close all directories in this directory node's cascade. This is
" necessary to ensure consistency when cascades are rendered.
for l:dirNode in self.getCascade()
let l:dirNode.isOpen = 0
endfor
endfunction
" FUNCTION: TreeDirNode.closeChildren() {{{1
@ -78,19 +83,29 @@ function! s:TreeDirNode.createChild(path, inOrder)
endfunction
" FUNCTION: TreeDirNode.displayString() {{{1
unlet s:TreeDirNode.displayString
" Assemble and return a string that can represent this TreeDirNode object in
" the NERDTree window.
function! s:TreeDirNode.displayString()
let cascade = self.getCascade()
let rv = ""
for node in cascade
let rv = rv . node.path.displayString()
let l:result = ''
" Build a label that identifies this TreeDirNode.
let l:label = ''
let l:cascade = self.getCascade()
for l:dirNode in l:cascade
let l:label .= l:dirNode.path.displayString()
endfor
let sym = cascade[-1].isOpen ? g:NERDTreeDirArrowCollapsible : g:NERDTreeDirArrowExpandable
" Select the appropriate open/closed status indicator symbol.
if l:cascade[-1].isOpen
let l:symbol = g:NERDTreeDirArrowCollapsible
else
let l:symbol = g:NERDTreeDirArrowExpandable
endif
let flags = cascade[-1].path.flagSet.renderToString()
let l:flags = l:cascade[-1].path.flagSet.renderToString()
return sym . ' ' . flags . rv
let l:result = l:symbol . ' ' . l:flags . l:label
return l:result
endfunction
" FUNCTION: TreeDirNode.findNode(path) {{{1
@ -400,25 +415,39 @@ function! s:TreeDirNode.New(path, nerdtree)
return newTreeNode
endfunction
" FUNCTION: TreeDirNode.open([opts]) {{{1
" Open the dir in the current tree or in a new tree elsewhere.
"
" If opening in the current tree, return the number of cached nodes.
unlet s:TreeDirNode.open
" FUNCTION: TreeDirNode.open([options]) {{{1
" Open this directory node in the current tree or elsewhere if special options
" are provided. Return 0 if options were processed. Otherwise, return the
" number of new cached nodes.
function! s:TreeDirNode.open(...)
let opts = a:0 ? a:1 : {}
let l:options = a:0 ? a:1 : {}
if has_key(opts, 'where') && !empty(opts['where'])
let opener = g:NERDTreeOpener.New(self.path, opts)
call opener.open(self)
else
let self.isOpen = 1
if self.children ==# []
return self._initChildren(0)
else
return 0
endif
" If special options were specified, process them and return.
if has_key(l:options, 'where') && !empty(l:options['where'])
let l:opener = g:NERDTreeOpener.New(self.path, l:options)
call l:opener.open(self)
return 0
endif
" Open any ancestors of this node that render within the same cascade.
let l:parent = self.parent
while !empty(l:parent) && !l:parent.isRoot()
if index(l:parent.getCascade(), self) >= 0
let l:parent.isOpen = 1
let l:parent = l:parent.parent
else
break
endif
endwhile
let self.isOpen = 1
let l:numChildrenCached = 0
if empty(self.children)
let l:numChildrenCached = self._initChildren(0)
endif
return l:numChildrenCached
endfunction
" FUNCTION: TreeDirNode.openAlong([opts]) {{{1
@ -463,35 +492,16 @@ function! s:TreeDirNode._openInNewTab()
endfunction
" FUNCTION: TreeDirNode.openRecursively() {{{1
" Opens this treenode and all of its children whose paths arent 'ignored'
" because of the file filters.
"
" This method is actually a wrapper for the OpenRecursively2 method which does
" the work.
" Open this directory node and any descendant directory nodes whose pathnames
" are not ignored.
function! s:TreeDirNode.openRecursively()
call self._openRecursively2(1)
endfunction
silent call self.open()
" FUNCTION: TreeDirNode._openRecursively2() {{{1
" Opens this all children of this treenode recursively if either:
" *they arent filtered by file filters
" *a:forceOpen is 1
"
" Args:
" forceOpen: 1 if this node should be opened regardless of file filters
function! s:TreeDirNode._openRecursively2(forceOpen)
if self.path.ignore(self.getNerdtree()) ==# 0 || a:forceOpen
let self.isOpen = 1
if self.children ==# []
call self._initChildren(1)
for l:child in self.children
if l:child.path.isDirectory && !l:child.path.ignore(l:child.getNerdtree())
call l:child.openRecursively()
endif
for i in self.children
if i.path.isDirectory ==# 1
call i._openRecursively2(0)
endif
endfor
endif
endfor
endfunction
" FUNCTION: TreeDirNode.refresh() {{{1