mirror of
https://github.com/preservim/nerdtree.git
synced 2025-11-08 11:23:48 -05:00
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:
@@ -19,9 +19,6 @@ function! s:Bookmark.AddBookmark(name, path)
|
||||
endif
|
||||
endfor
|
||||
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
|
||||
|
||||
" 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.")
|
||||
endif
|
||||
endif
|
||||
if g:NERDTreeBookmarksSort == 1 || g:NERDTreeBookmarksSort == 2
|
||||
call s:Bookmark.SortBookmarksList()
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -313,6 +313,10 @@ function! s:UI._renderBookmarks()
|
||||
call cursor(line(".")+1, col("."))
|
||||
endif
|
||||
|
||||
if g:NERDTreeBookmarksSort == 1 || g:NERDTreeBookmarksSort == 2
|
||||
call g:NERDTreeBookmark.SortBookmarksList()
|
||||
endif
|
||||
|
||||
for i in g:NERDTreeBookmark.Bookmarks()
|
||||
call setline(line(".")+1, i.str())
|
||||
call cursor(line(".")+1, col("."))
|
||||
|
||||
Reference in New Issue
Block a user