From 2a7a375729dc04bfcbb0411d00839e5349f59193 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Fri, 26 May 2017 13:46:09 -0400 Subject: [PATCH] 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. --- lib/nerdtree/bookmark.vim | 6 ------ lib/nerdtree/ui.vim | 4 ++++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/nerdtree/bookmark.vim b/lib/nerdtree/bookmark.vim index 8bd95fe..ad8c3d1 100644 --- a/lib/nerdtree/bookmark.vim +++ b/lib/nerdtree/bookmark.vim @@ -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 diff --git a/lib/nerdtree/ui.vim b/lib/nerdtree/ui.vim index 65ebfd9..e169dbb 100644 --- a/lib/nerdtree/ui.vim +++ b/lib/nerdtree/ui.vim @@ -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("."))