[Buffers] Use reltimefloat(reltime()) instead of localtime() (#152)
* Nanoseconds instead of seconds for buffer timestmaps Fzf :Buffers uses a dictionary where it stores the last time accessed of the current buffers. This is used to sort the buffers. The timestamp is retrieved from a call to localtime() which returns the current second the buffer is accessed. However, fzf functions in such a way that before it enters the newly selected buffer, it enters the current buffer. Sometimes this causes the last two buffers to have the same timestamp. Repeatedly switching between two buffers yields inconsistent results. This commit fixes the issue by using seconds and microseconds from the bash call `date`. The buffers are now guaranteed to be sorted by last accessed. * Use reltime() instead of linux date This solution is better for compatability reasons. * Remove trailing whitespace
This commit is contained in:
parent
0897718523
commit
60aaf2624c
2 changed files with 3 additions and 2 deletions
|
@ -479,7 +479,8 @@ endfunction
|
|||
|
||||
function! s:sort_buffers(...)
|
||||
let [b1, b2] = map(copy(a:000), 'get(g:fzf#vim#buffers, v:val, v:val)')
|
||||
return b1 - b2
|
||||
" Using minus between a float and a number in a sort function causes an error
|
||||
return b1 > b2 ? 1 : -1
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#buffers(...)
|
||||
|
|
|
@ -112,7 +112,7 @@ endif
|
|||
let g:fzf#vim#buffers = {}
|
||||
augroup fzf_buffers
|
||||
autocmd!
|
||||
autocmd BufWinEnter,WinEnter * let g:fzf#vim#buffers[bufnr('')] = localtime()
|
||||
autocmd BufWinEnter,WinEnter * let g:fzf#vim#buffers[bufnr('')] = reltimefloat(reltime())
|
||||
autocmd BufDelete * silent! call remove(g:fzf#vim#buffers, expand('<abuf>'))
|
||||
augroup END
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue