Merge pull request #856 from scrooloose/broken_sort_#277
Fix issues with sorting of nodes
This commit is contained in:
commit
eee179f0bf
@ -61,7 +61,6 @@ endfunction
|
|||||||
function! nerdtree#compareNodesBySortKey(n1, n2)
|
function! nerdtree#compareNodesBySortKey(n1, n2)
|
||||||
let sortKey1 = a:n1.path.getSortKey()
|
let sortKey1 = a:n1.path.getSortKey()
|
||||||
let sortKey2 = a:n2.path.getSortKey()
|
let sortKey2 = a:n2.path.getSortKey()
|
||||||
|
|
||||||
let i = 0
|
let i = 0
|
||||||
while i < min([len(sortKey1), len(sortKey2)])
|
while i < min([len(sortKey1), len(sortKey2)])
|
||||||
" Compare chunks upto common length.
|
" Compare chunks upto common length.
|
||||||
@ -73,9 +72,9 @@ function! nerdtree#compareNodesBySortKey(n1, n2)
|
|||||||
elseif sortKey1[i] ># sortKey2[i]
|
elseif sortKey1[i] ># sortKey2[i]
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
elseif sortKey1[i] == type(0)
|
elseif type(sortKey1[i]) == v:t_number
|
||||||
return -1
|
return -1
|
||||||
elseif sortKey2[i] == type(0)
|
elseif type(sortKey2[i]) == v:t_number
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
let i = i + 1
|
let i = i + 1
|
||||||
|
@ -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 s:Path = {}
|
||||||
let g:NERDTreePath = s:Path
|
let g:NERDTreePath = s:Path
|
||||||
|
|
||||||
@ -374,7 +370,8 @@ function! s:Path.getSortOrderIndex()
|
|||||||
endif
|
endif
|
||||||
let i = i + 1
|
let i = i + 1
|
||||||
endwhile
|
endwhile
|
||||||
return s:NERDTreeSortStarIndex
|
|
||||||
|
return index(g:NERDTreeSortOrder, '*')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: Path._splitChunks(path) {{{1
|
" FUNCTION: Path._splitChunks(path) {{{1
|
||||||
@ -395,7 +392,7 @@ endfunction
|
|||||||
" FUNCTION: Path.getSortKey() {{{1
|
" FUNCTION: Path.getSortKey() {{{1
|
||||||
" returns a key used in compare function for sorting
|
" returns a key used in compare function for sorting
|
||||||
function! s:Path.getSortKey()
|
function! s:Path.getSortKey()
|
||||||
if !exists("self._sortKey")
|
if !exists("self._sortKey") || g:NERDTreeSortOrder !=# g:NERDTreeOldSortOrder
|
||||||
let path = self.getLastPathComponent(1)
|
let path = self.getLastPathComponent(1)
|
||||||
if !g:NERDTreeSortHiddenFirst
|
if !g:NERDTreeSortHiddenFirst
|
||||||
let path = substitute(path, '^[._]', '', '')
|
let path = substitute(path, '^[._]', '', '')
|
||||||
|
@ -607,8 +607,12 @@ endfunction
|
|||||||
" FUNCTION: TreeDirNode.sortChildren() {{{1
|
" FUNCTION: TreeDirNode.sortChildren() {{{1
|
||||||
" Sort "self.children" by alphabetical order and directory priority.
|
" Sort "self.children" by alphabetical order and directory priority.
|
||||||
function! s:TreeDirNode.sortChildren()
|
function! s:TreeDirNode.sortChildren()
|
||||||
|
if count(g:NERDTreeSortOrder, '*') < 1
|
||||||
|
call add(g:NERDTreeSortOrder, '*')
|
||||||
|
endif
|
||||||
let CompareFunc = function("nerdtree#compareNodesBySortKey")
|
let CompareFunc = function("nerdtree#compareNodesBySortKey")
|
||||||
call sort(self.children, CompareFunc)
|
call sort(self.children, CompareFunc)
|
||||||
|
let g:NERDTreeOldSortOrder = g:NERDTreeSortOrder
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: TreeDirNode.toggleOpen([options]) {{{1
|
" FUNCTION: TreeDirNode.toggleOpen([options]) {{{1
|
||||||
|
@ -81,12 +81,8 @@ call s:initVariable("g:NERDTreeCascadeSingleChildDir", 1)
|
|||||||
|
|
||||||
if !exists("g:NERDTreeSortOrder")
|
if !exists("g:NERDTreeSortOrder")
|
||||||
let g:NERDTreeSortOrder = ['\/$', '*', '\.swp$', '\.bak$', '\~$']
|
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
|
endif
|
||||||
|
let g:NERDTreeOldSortOrder = []
|
||||||
|
|
||||||
call s:initVariable("g:NERDTreeGlyphReadOnly", "RO")
|
call s:initVariable("g:NERDTreeGlyphReadOnly", "RO")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user