Fix issues with sorting of nodes
This commit is contained in:
Phil Runninger 2018-07-31 14:53:40 -04:00 committed by GitHub
commit eee179f0bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 14 deletions

View File

@ -61,7 +61,6 @@ endfunction
function! nerdtree#compareNodesBySortKey(n1, n2)
let sortKey1 = a:n1.path.getSortKey()
let sortKey2 = a:n2.path.getSortKey()
let i = 0
while i < min([len(sortKey1), len(sortKey2)])
" Compare chunks upto common length.
@ -73,9 +72,9 @@ function! nerdtree#compareNodesBySortKey(n1, n2)
elseif sortKey1[i] ># sortKey2[i]
return 1
endif
elseif sortKey1[i] == type(0)
elseif type(sortKey1[i]) == v:t_number
return -1
elseif sortKey2[i] == type(0)
elseif type(sortKey2[i]) == v:t_number
return 1
endif
let i = i + 1

View File

@ -7,10 +7,6 @@
" ============================================================================
" This constant is used throughout this script for sorting purposes.
let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*')
lockvar s:NERDTreeSortStarIndex
let s:Path = {}
let g:NERDTreePath = s:Path
@ -374,7 +370,8 @@ function! s:Path.getSortOrderIndex()
endif
let i = i + 1
endwhile
return s:NERDTreeSortStarIndex
return index(g:NERDTreeSortOrder, '*')
endfunction
" FUNCTION: Path._splitChunks(path) {{{1
@ -395,7 +392,7 @@ endfunction
" FUNCTION: Path.getSortKey() {{{1
" returns a key used in compare function for sorting
function! s:Path.getSortKey()
if !exists("self._sortKey")
if !exists("self._sortKey") || g:NERDTreeSortOrder !=# g:NERDTreeOldSortOrder
let path = self.getLastPathComponent(1)
if !g:NERDTreeSortHiddenFirst
let path = substitute(path, '^[._]', '', '')

View File

@ -607,8 +607,12 @@ endfunction
" FUNCTION: TreeDirNode.sortChildren() {{{1
" Sort "self.children" by alphabetical order and directory priority.
function! s:TreeDirNode.sortChildren()
if count(g:NERDTreeSortOrder, '*') < 1
call add(g:NERDTreeSortOrder, '*')
endif
let CompareFunc = function("nerdtree#compareNodesBySortKey")
call sort(self.children, CompareFunc)
let g:NERDTreeOldSortOrder = g:NERDTreeSortOrder
endfunction
" FUNCTION: TreeDirNode.toggleOpen([options]) {{{1

View File

@ -81,12 +81,8 @@ call s:initVariable("g:NERDTreeCascadeSingleChildDir", 1)
if !exists("g:NERDTreeSortOrder")
let g:NERDTreeSortOrder = ['\/$', '*', '\.swp$', '\.bak$', '\~$']
else
"if there isnt a * in the sort sequence then add one
if count(g:NERDTreeSortOrder, '*') < 1
call add(g:NERDTreeSortOrder, '*')
endif
endif
let g:NERDTreeOldSortOrder = []
call s:initVariable("g:NERDTreeGlyphReadOnly", "RO")