Remove code duplication from sorting bookmarks

It makes the most sense to sort the global bookmarks list just before
rendering them in the NERDTree window. Since Vim's sort function is fast
and stable, and since users are very unlikely to have a number of
bookmarks that is too large, we can sort before rendering without
concern for the negligible performance penalty.

This has two benefits:
  1. Users can change their sort settings and have them take effect
     on the next render or refresh.
  2. As mentioned, code duplication is avoided.
This commit is contained in:
Jason Franklin
2017-05-26 13:46:09 -04:00
parent 0b65089122
commit 2a7a375729
2 changed files with 4 additions and 6 deletions

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 || g:NERDTreeBookmarksSort == 2
call s:Bookmark.SortBookmarksList()
endif
endfunction endfunction
" FUNCTION: Bookmark.Bookmarks() {{{1 " FUNCTION: Bookmark.Bookmarks() {{{1
@@ -104,9 +101,6 @@ 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 || g:NERDTreeBookmarksSort == 2
call s:Bookmark.SortBookmarksList()
endif
endif endif
endfunction endfunction

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("."))