Skip to content

Commit 2a7a375

Browse files
author
Jason Franklin
committed
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.
1 parent 0b65089 commit 2a7a375

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

lib/nerdtree/bookmark.vim

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ function! s:Bookmark.AddBookmark(name, path)
1919
endif
2020
endfor
2121
call add(s:Bookmark.Bookmarks(), s:Bookmark.New(a:name, a:path))
22-
if g:NERDTreeBookmarksSort == 1 || g:NERDTreeBookmarksSort == 2
23-
call s:Bookmark.SortBookmarksList()
24-
endif
2522
endfunction
2623

2724
" FUNCTION: Bookmark.Bookmarks() {{{1
@@ -104,9 +101,6 @@ function! s:Bookmark.CacheBookmarks(silent)
104101
call nerdtree#echo(invalidBookmarksFound . " invalid bookmarks were read. See :help NERDTreeInvalidBookmarks for info.")
105102
endif
106103
endif
107-
if g:NERDTreeBookmarksSort == 1 || g:NERDTreeBookmarksSort == 2
108-
call s:Bookmark.SortBookmarksList()
109-
endif
110104
endif
111105
endfunction
112106

lib/nerdtree/ui.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ function! s:UI._renderBookmarks()
313313
call cursor(line(".")+1, col("."))
314314
endif
315315

316+
if g:NERDTreeBookmarksSort == 1 || g:NERDTreeBookmarksSort == 2
317+
call g:NERDTreeBookmark.SortBookmarksList()
318+
endif
319+
316320
for i in g:NERDTreeBookmark.Bookmarks()
317321
call setline(line(".")+1, i.str())
318322
call cursor(line(".")+1, col("."))

0 commit comments

Comments
 (0)