From 18f04e082493c553f5f5e3323a1b84c12d77cc24 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Thu, 29 Jun 2017 17:53:47 -0400 Subject: [PATCH 1/6] Refactor the "TreeDirNode.displayString()" method I found this method to be unreadable and cumbersome. Cleaning it up helped me to understand the design ideas behind it. --- lib/nerdtree/tree_dir_node.vim | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim index 61f72e4..70fa1aa 100644 --- a/lib/nerdtree/tree_dir_node.vim +++ b/lib/nerdtree/tree_dir_node.vim @@ -78,19 +78,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 From 86605413339960e0f32e5197d1d38b547bf141cf Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Sun, 2 Jul 2017 11:51:32 -0400 Subject: [PATCH 2/6] Fix the "TreeDirNode.open()" method Issues #547 and #526 reported a problem with the "open()" method in the "TreeDirNode" class. Specifically, opening a cascade in the NERDTree will perform the opening operation on the tail of the cascade. This is a problem when other operations (such as the "u" mapping) close intermediate cascaded directories, which causes opening the tail to have no effect (other than toggling the arrow). Here, the "open()" method was modified to open all directories in a cascade whenever the tail is opened. This is the only reasonable fix for this type of problem. Fixes #547 and fixes #526. --- lib/nerdtree/tree_dir_node.vim | 46 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim index 70fa1aa..19597f5 100644 --- a/lib/nerdtree/tree_dir_node.vim +++ b/lib/nerdtree/tree_dir_node.vim @@ -410,25 +410,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 l:parent != b:NERDTree.root && !empty(l:parent) + 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 From ebc206e58d959dd244ddbb82e5e784d51b6c2c6b Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Sun, 2 Jul 2017 12:03:45 -0400 Subject: [PATCH 3/6] Refactor "TreeDirNode.close()" method This method required adjustment to take cascades into consideration. Since the arrow in the NERDTree window reflects the status of the tail directory of the associated cascade, an arrow indicating open status can be present when a higher directory in the cascade was closed. This commit will automatically close child nodes within the same cascade of a closed directory node so that the arrow accurately reflects what is rendered. --- lib/nerdtree/tree_dir_node.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim index 19597f5..ac89c82 100644 --- a/lib/nerdtree/tree_dir_node.vim +++ b/lib/nerdtree/tree_dir_node.vim @@ -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 From 7f4a7205dca12736b7fb03334b57ab3342c56b0d Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Sun, 2 Jul 2017 14:57:33 -0400 Subject: [PATCH 4/6] Replace an equality test with an instance method A proper instance method was substituted for the more brittle equality test in the "TreeDirNode.open()" method. Note that the order of the tests was reversed to account for the fact that the "isRoot()" method can only be called after the first test has passed. --- lib/nerdtree/tree_dir_node.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim index ac89c82..5c9fe72 100644 --- a/lib/nerdtree/tree_dir_node.vim +++ b/lib/nerdtree/tree_dir_node.vim @@ -431,7 +431,7 @@ function! s:TreeDirNode.open(...) " Open any ancestors of this node that render within the same cascade. let l:parent = self.parent - while l:parent != b:NERDTree.root && !empty(l: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 From ef35ee891870a6f2cff856c71849f8307e623a5c Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Tue, 4 Jul 2017 09:45:06 -0400 Subject: [PATCH 5/6] Remove the helper function for "openRecursively()" The support function for this method was unnecessary, so I took the time to remove it. Since "TreeDirNode.openRecursively()" now calls the "open()" method, it can take advantage of the improvements made to that function in recent commits. Specifically, this method will reflect the bugfix provided in pull request #720. --- lib/nerdtree/tree_dir_node.vim | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim index 5c9fe72..5ca94d4 100644 --- a/lib/nerdtree/tree_dir_node.vim +++ b/lib/nerdtree/tree_dir_node.vim @@ -492,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 From c1b71dcfc5aaf9140361a1631a06a9dd5c88e526 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Tue, 4 Jul 2017 10:14:35 -0400 Subject: [PATCH 6/6] Rename the help file to "NERDTree.txt" I thought renaming this file was important so that the NERDTree name is printed with consistency. Branding is important. --- README.markdown | 2 +- doc/{NERD_tree.txt => NERDTree.txt} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename doc/{NERD_tree.txt => NERDTree.txt} (99%) diff --git a/README.markdown b/README.markdown index 19b841b..48d216b 100644 --- a/README.markdown +++ b/README.markdown @@ -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) diff --git a/doc/NERD_tree.txt b/doc/NERDTree.txt similarity index 99% rename from doc/NERD_tree.txt rename to doc/NERDTree.txt index 427e90c..f68880c 100644 --- a/doc/NERD_tree.txt +++ b/doc/NERDTree.txt @@ -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!