From f98078d3ae6d356fcc58a4fc8840eb55b1ea522e Mon Sep 17 00:00:00 2001 From: Phil Runninger Date: Thu, 18 Oct 2018 16:13:15 -0400 Subject: [PATCH] Force sort to recalculate the cached sortKey. (#898) * Force sort to recalculate the cached sortKey. The problem in issue #880 was caused by the sort using the old sortKey. For example, given nodes A, B, and C, if B were renamed to D, the sort was still using B as its sortKey, thus not moving it. It's a bit of a hack, but if we set g:NERDTreeOldSortOrder to an empty list, the cached sortKey will be recalculated. I did the same thing for both the Copy and Add functions as well. * Add a comment to explain the let ... = [] statement. --- nerdtree_plugin/fs_menu.vim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nerdtree_plugin/fs_menu.vim b/nerdtree_plugin/fs_menu.vim index f6249f9..ef378e2 100644 --- a/nerdtree_plugin/fs_menu.vim +++ b/nerdtree_plugin/fs_menu.vim @@ -128,6 +128,9 @@ function! NERDTreeAddNode() let parentNode = b:NERDTree.root.findNode(newPath.getParent()) let newTreeNode = g:NERDTreeFileNode.New(newPath, b:NERDTree) + " Emptying g:NERDTreeOldSortOrder forces the sort to + " recalculate the cached sortKey so nodes sort correctly. + let g:NERDTreeOldSortOrder = [] if empty(parentNode) call b:NERDTree.root.refresh() call b:NERDTree.render() @@ -158,6 +161,9 @@ function! NERDTreeMoveNode() let bufnum = bufnr("^".curNode.path.str()."$") call curNode.rename(newNodePath) + " Emptying g:NERDTreeOldSortOrder forces the sort to + " recalculate the cached sortKey so nodes sort correctly. + let g:NERDTreeOldSortOrder = [] call b:NERDTree.root.refresh() call NERDTreeRender() @@ -283,6 +289,9 @@ function! NERDTreeCopyNode() if confirmed try let newNode = currentNode.copy(newNodePath) + " Emptying g:NERDTreeOldSortOrder forces the sort to + " recalculate the cached sortKey so nodes sort correctly. + let g:NERDTreeOldSortOrder = [] if empty(newNode) call b:NERDTree.root.refresh() call b:NERDTree.render()