فهرست منبع

Gather logic to clear excess lines into `s:BuildBufferList()`.

`s:ToggleOnlyOneTab()` lacked the optional parameter to
`s:RebuildBufferList()` required to remove excess lines when the number
of displayed buffers is expected to decrease.  Rather than add this
logic, remove the optional argument from `s:RebuildBufferList()` and
adjust `s:BuildBufferList()` to remove any excess lines in the event
that the line count is too large.  This unburdens callers of
`s:RebuildBufferList()` from the responsibility of determining how any
changes they've made will impact the number of lines in the buffer list.
Michael Henry 10 ماه پیش
والد
کامیت
b58b623803
1فایلهای تغییر یافته به همراه8 افزوده شده و 8 حذف شده
  1. 8 8
      plugin/bufexplorer.vim

+ 8 - 8
plugin/bufexplorer.vim

@@ -808,6 +808,11 @@ function! s:BuildBufferList()
 
     let lines = s:MakeLines(table)
     call setline(s:firstBufferLine, lines)
+    let firstMissingLine = s:firstBufferLine + len(lines)
+    if line('$') >= firstMissingLine
+        " Clear excess lines starting with `firstMissingLine`.
+        execute "silent keepjumps ".firstMissingLine.',$d _'
+    endif
     call s:SortListing()
 endfunction
 
@@ -1095,7 +1100,7 @@ endfunction
 " ToggleShowTabBuffer {{{2
 function! s:ToggleShowTabBuffer()
     let g:bufExplorerShowTabBuffer = !g:bufExplorerShowTabBuffer
-    call s:RebuildBufferList(g:bufExplorerShowTabBuffer)
+    call s:RebuildBufferList()
     call s:UpdateHelpStatus()
 endfunction
 
@@ -1109,7 +1114,7 @@ endfunction
 " ToggleShowUnlisted {{{2
 function! s:ToggleShowUnlisted()
     let g:bufExplorerShowUnlisted = !g:bufExplorerShowUnlisted
-    let num_bufs = s:RebuildBufferList(g:bufExplorerShowUnlisted == 0)
+    let num_bufs = s:RebuildBufferList()
     call s:UpdateHelpStatus()
 endfunction
 
@@ -1120,16 +1125,11 @@ function! s:ToggleFindActive()
 endfunction
 
 " RebuildBufferList {{{2
-function! s:RebuildBufferList(...)
+function! s:RebuildBufferList()
     setlocal modifiable
 
     let curPos = getpos('.')
 
-    if a:0 && a:000[0] && (line('$') >= s:firstBufferLine)
-        " Clear the list first.
-        execute "silent keepjumps ".s:firstBufferLine.',$d _'
-    endif
-
     let num_bufs = s:BuildBufferList()
 
     call setpos('.', curPos)