nerdtree

A tree explorer plugin for vim.
Index Commits Files Refs
commit f98078d3ae6d356fcc58a4fc8840eb55b1ea522e
parent 820955e77308d2c3d324bde152c0dca9d69c735f
Author: Phil Runninger <PhilRunninger@users.noreply.github.com>
Date:   Thu, 18 Oct 2018 16:13:15 -0400

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.

Diffstat:
Mnerdtree_plugin/fs_menu.vim | 9+++++++++
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git 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()