mirror of
https://github.com/preservim/nerdtree.git
synced 2024-11-26 10:14:20 +08:00
Recalculate the node's sortkey every time.
The cached _sortkey wasn't being recalculated after changing the NERDTreeSortOrder, resulting in incorrect sort orders.
This commit is contained in:
parent
703e1ef4fe
commit
a053925279
|
@ -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,6 @@ 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")
|
|
||||||
let path = self.getLastPathComponent(1)
|
let path = self.getLastPathComponent(1)
|
||||||
if !g:NERDTreeSortHiddenFirst
|
if !g:NERDTreeSortHiddenFirst
|
||||||
let path = substitute(path, '^[._]', '', '')
|
let path = substitute(path, '^[._]', '', '')
|
||||||
|
@ -408,7 +404,6 @@ function! s:Path.getSortKey()
|
||||||
else
|
else
|
||||||
let self._sortKey = [self.getSortOrderIndex()] + self._splitChunks(path)
|
let self._sortKey = [self.getSortOrderIndex()] + self._splitChunks(path)
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
return self._sortKey
|
return self._sortKey
|
||||||
endfunction
|
endfunction
|
||||||
|
|
|
@ -607,6 +607,7 @@ 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()
|
||||||
|
call AddDefaultGroupToSortOrder()
|
||||||
let CompareFunc = function("nerdtree#compareNodesBySortKey")
|
let CompareFunc = function("nerdtree#compareNodesBySortKey")
|
||||||
call sort(self.children, CompareFunc)
|
call sort(self.children, CompareFunc)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
|
@ -24,6 +24,15 @@ let loaded_nerd_tree = 1
|
||||||
let s:old_cpo = &cpo
|
let s:old_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
|
"Function: AddDefaultGroupToSortOrder() function {{{2
|
||||||
|
"This function adds the default grouping '*' to the sort sequence if it's not
|
||||||
|
"already in the list.
|
||||||
|
function! AddDefaultGroupToSortOrder()
|
||||||
|
if count(g:NERDTreeSortOrder, '*') < 1
|
||||||
|
call add(g:NERDTreeSortOrder, '*')
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
"Function: s:initVariable() function {{{2
|
"Function: s:initVariable() function {{{2
|
||||||
"This function is used to initialise a given variable to a given value. The
|
"This function is used to initialise a given variable to a given value. The
|
||||||
"variable is only initialised if it does not exist prior
|
"variable is only initialised if it does not exist prior
|
||||||
|
@ -82,10 +91,7 @@ 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
|
else
|
||||||
"if there isnt a * in the sort sequence then add one
|
call AddDefaultGroupToSortOrder()
|
||||||
if count(g:NERDTreeSortOrder, '*') < 1
|
|
||||||
call add(g:NERDTreeSortOrder, '*')
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call s:initVariable("g:NERDTreeGlyphReadOnly", "RO")
|
call s:initVariable("g:NERDTreeGlyphReadOnly", "RO")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user