From cedb40b4f584948133af1939247131a632837021 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Mon, 16 Nov 2015 13:17:59 +0000 Subject: [PATCH] move TreeFileNode.makeRoot() to NERDTree.changeRoot(node) --- autoload/nerdtree/ui_glue.vim | 4 +--- lib/nerdtree/bookmark.vim | 4 +--- lib/nerdtree/nerdtree.vim | 22 ++++++++++++++++++++++ lib/nerdtree/opener.vim | 4 +--- lib/nerdtree/tree_file_node.vim | 20 -------------------- 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 23edfe7..604a637 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -140,9 +140,7 @@ endfunction " FUNCTION: s:chRoot(node) {{{1 " changes the current root to the selected one function! s:chRoot(node) - call a:node.makeRoot() - call b:NERDTree.render() - call b:NERDTree.root.putCursorHere(0, 0) + call b:NERDTree.changeRoot(a:node) endfunction " FUNCTION: s:nerdtree#ui_glue#chRootCwd() {{{1 diff --git a/lib/nerdtree/bookmark.vim b/lib/nerdtree/bookmark.vim index 1b49f02..f481501 100644 --- a/lib/nerdtree/bookmark.vim +++ b/lib/nerdtree/bookmark.vim @@ -275,9 +275,7 @@ function! s:Bookmark.toRoot() catch /^NERDTree.BookmarkedNodeNotFoundError/ let targetNode = g:NERDTreeFileNode.New(s:Bookmark.BookmarkFor(self.name).path) endtry - call targetNode.makeRoot() - call b:NERDTree.render() - call targetNode.putCursorHere(0, 0) + call b:NERDTree.changeRoot(targetNode) endif endfunction diff --git a/lib/nerdtree/nerdtree.vim b/lib/nerdtree/nerdtree.vim index 83468ca..9e38b3a 100644 --- a/lib/nerdtree/nerdtree.vim +++ b/lib/nerdtree/nerdtree.vim @@ -8,6 +8,28 @@ function! s:NERDTree.AddPathFilter(callback) call add(s:NERDTree.PathFilters(), a:callback) endfunction +"FUNCTION: s:NERDTree.changeRoot(node) {{{1 +function! s:NERDTree.changeRoot(node) + if a:node.path.isDirectory + let self.root = a:node + else + call a:node.cacheParent() + let self.root = self.parent + endif + + call self.root.open() + + "change dir to the dir of the new root if instructed to + if g:NERDTreeChDirMode ==# 2 + exec "cd " . self.root.path.str({'format': 'Edit'}) + endif + + call self.render() + call self.root.putCursorHere(0, 0) + + silent doautocmd User NERDTreeNewRoot +endfunction + "FUNCTION: s:NERDTree.Close() {{{1 "Closes the tab tree window for this tab function! s:NERDTree.Close() diff --git a/lib/nerdtree/opener.vim b/lib/nerdtree/opener.vim index 0f8a005..480d91d 100644 --- a/lib/nerdtree/opener.vim +++ b/lib/nerdtree/opener.vim @@ -268,9 +268,7 @@ function! s:Opener._openDirectory(node) else call self._gotoTargetWin() if empty(self._where) - call a:node.makeRoot() - call b:NERDTree.render() - call a:node.putCursorHere(0, 0) + call b:NERDTree.changeRoot(a:node) elseif self._where == 't' call g:NERDTreeCreator.CreateTabTree(a:node.path.str()) else diff --git a/lib/nerdtree/tree_file_node.vim b/lib/nerdtree/tree_file_node.vim index b2a536e..150b03a 100644 --- a/lib/nerdtree/tree_file_node.vim +++ b/lib/nerdtree/tree_file_node.vim @@ -218,26 +218,6 @@ function! s:TreeFileNode.isRoot() return self.equals(b:NERDTree.root) endfunction -"FUNCTION: TreeFileNode.makeRoot() {{{1 -"Make this node the root of the tree -function! s:TreeFileNode.makeRoot() - if self.path.isDirectory - let b:NERDTree.root = self - else - call self.cacheParent() - let b:NERDTree.root = self.parent - endif - - call b:NERDTree.root.open() - - "change dir to the dir of the new root if instructed to - if g:NERDTreeChDirMode ==# 2 - exec "cd " . b:NERDTree.root.path.str({'format': 'Edit'}) - endif - - silent doautocmd User NERDTreeNewRoot -endfunction - "FUNCTION: TreeFileNode.New(path) {{{1 "Returns a new TreeNode object with the given path and parent "