Merge pull request #696 from lifecrisis/issue361

BUGFIX: Broken "g:NERDTreeBookmarksSort" setting fixed.
This commit is contained in:
Phil Runninger
2017-05-26 14:27:14 -04:00
committed by GitHub
4 changed files with 45 additions and 31 deletions

View File

@@ -52,11 +52,6 @@ function! nerdtree#completeBookmarks(A,L,P)
return filter(g:NERDTreeBookmark.BookmarkNames(), 'v:val =~# "^' . a:A . '"') return filter(g:NERDTreeBookmark.BookmarkNames(), 'v:val =~# "^' . a:A . '"')
endfunction endfunction
"FUNCTION: nerdtree#compareBookmarks(dir) {{{2
function! nerdtree#compareBookmarks(first, second)
return a:first.compareTo(a:second)
endfunction
"FUNCTION: nerdtree#compareNodes(dir) {{{2 "FUNCTION: nerdtree#compareNodes(dir) {{{2
function! nerdtree#compareNodes(n1, n2) function! nerdtree#compareNodes(n1, n2)
return a:n1.path.compareTo(a:n2.path) return a:n1.path.compareTo(a:n2.path)

View File

@@ -835,11 +835,15 @@ This is where bookmarks are saved. See |NERDTreeBookmarkCommands|.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*'NERDTreeBookmarksSort'* *'NERDTreeBookmarksSort'*
Values: 0 or 1 Values: 0, 1, or 2
Default: 1 Default: 1
If set to 0 then the bookmarks list is not sorted. This option controls the method by which the list of user bookmarks is
If set to 1 the bookmarks list is sorted. sorted. When sorted, bookmarks will render in alphabetical order by name.
If set to 0, the bookmarks list is not sorted.
If set to 1, the bookmarks list is sorted in a case-insensitive manner.
If set to 2, the bookmarks list is sorted in a case-sensitive manner.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*'NERDTreeMouseMode'* *'NERDTreeMouseMode'*

View File

@@ -19,9 +19,6 @@ function! s:Bookmark.AddBookmark(name, path)
endif endif
endfor endfor
call add(s:Bookmark.Bookmarks(), s:Bookmark.New(a:name, a:path)) call add(s:Bookmark.Bookmarks(), s:Bookmark.New(a:name, a:path))
if g:NERDTreeBookmarksSort ==# 1
call s:Bookmark.Sort()
endif
endfunction endfunction
" FUNCTION: Bookmark.Bookmarks() {{{1 " FUNCTION: Bookmark.Bookmarks() {{{1
@@ -104,17 +101,31 @@ function! s:Bookmark.CacheBookmarks(silent)
call nerdtree#echo(invalidBookmarksFound . " invalid bookmarks were read. See :help NERDTreeInvalidBookmarks for info.") call nerdtree#echo(invalidBookmarksFound . " invalid bookmarks were read. See :help NERDTreeInvalidBookmarks for info.")
endif endif
endif endif
if g:NERDTreeBookmarksSort ==# 1
call s:Bookmark.Sort()
endif
endif endif
endfunction endfunction
" FUNCTION: Bookmark.compareTo(otherbookmark) {{{1 " FUNCTION: Bookmark.CompareBookmarksByName(firstBookmark, secondBookmark) {{{1
" Compare these two bookmarks for sorting purposes " Class method that indicates the relative position of two bookmarks when
function! s:Bookmark.compareTo(otherbookmark) " placed in alphabetical order by name. Case-sensitivity is determined by an
return a:otherbookmark.name < self.name " option. Supports the "s:Bookmark.SortBookmarksList()" method.
function! s:Bookmark.CompareBookmarksByName(firstBookmark, secondBookmark)
let l:result = 0
if g:NERDTreeBookmarksSort == 1
if a:firstBookmark.name <? a:secondBookmark.name
let l:result = -1
elseif a:firstBookmark.name >? a:secondBookmark.name
let l:result = 1
endif
elseif g:NERDTreeBookmarksSort == 2
if a:firstBookmark.name <# a:secondBookmark.name
let l:result = -1
elseif a:firstBookmark.name ># a:secondBookmark.name
let l:result = 1
endif
endif
return l:result
endfunction endfunction
" FUNCTION: Bookmark.ClearAll() {{{1 " FUNCTION: Bookmark.ClearAll() {{{1
" Class method to delete all bookmarks. " Class method to delete all bookmarks.
function! s:Bookmark.ClearAll() function! s:Bookmark.ClearAll()
@@ -239,11 +250,11 @@ function! s:Bookmark.setPath(path)
let self.path = a:path let self.path = a:path
endfunction endfunction
" FUNCTION: Bookmark.Sort() {{{1 " FUNCTION: Bookmark.SortBookmarksList() {{{1
" Class method that sorts all bookmarks " Class method that sorts the global list of bookmarks alphabetically by name.
function! s:Bookmark.Sort() " Note that case-sensitivity is determined by a user option.
let CompareFunc = function("nerdtree#compareBookmarks") function! s:Bookmark.SortBookmarksList()
call sort(s:Bookmark.Bookmarks(), CompareFunc) call sort(s:Bookmark.Bookmarks(), s:Bookmark.CompareBookmarksByName)
endfunction endfunction
" FUNCTION: Bookmark.str() {{{1 " FUNCTION: Bookmark.str() {{{1

View File

@@ -313,6 +313,10 @@ function! s:UI._renderBookmarks()
call cursor(line(".")+1, col(".")) call cursor(line(".")+1, col("."))
endif endif
if g:NERDTreeBookmarksSort == 1 || g:NERDTreeBookmarksSort == 2
call g:NERDTreeBookmark.SortBookmarksList()
endif
for i in g:NERDTreeBookmark.Bookmarks() for i in g:NERDTreeBookmark.Bookmarks()
call setline(line(".")+1, i.str()) call setline(line(".")+1, i.str())
call cursor(line(".")+1, col(".")) call cursor(line(".")+1, col("."))