diff --git a/autoload/nerdtree.vim b/autoload/nerdtree.vim index b138c21..bdf3deb 100644 --- a/autoload/nerdtree.vim +++ b/autoload/nerdtree.vim @@ -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 diff --git a/lib/nerdtree/path.vim b/lib/nerdtree/path.vim index 2d8de23..0aa592e 100644 --- a/lib/nerdtree/path.vim +++ b/lib/nerdtree/path.vim @@ -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, '^[._]', '', '') diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim index 03c3545..30db853 100644 --- a/lib/nerdtree/tree_dir_node.vim +++ b/lib/nerdtree/tree_dir_node.vim @@ -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 diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 35b47c3..71d719a 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -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")