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.
This commit is contained in:
Phil Runninger 2018-10-18 16:13:15 -04:00 committed by GitHub
parent 820955e773
commit f98078d3ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()