mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-07 05:04:30 +08:00
[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:
committed by
Junegunn Choi
parent
0897718523
commit
60aaf2624c
@@ -479,7 +479,8 @@ endfunction
|
|||||||
|
|
||||||
function! s:sort_buffers(...)
|
function! s:sort_buffers(...)
|
||||||
let [b1, b2] = map(copy(a:000), 'get(g:fzf#vim#buffers, v:val, v:val)')
|
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
|
endfunction
|
||||||
|
|
||||||
function! fzf#vim#buffers(...)
|
function! fzf#vim#buffers(...)
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ endif
|
|||||||
let g:fzf#vim#buffers = {}
|
let g:fzf#vim#buffers = {}
|
||||||
augroup fzf_buffers
|
augroup fzf_buffers
|
||||||
autocmd!
|
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>'))
|
autocmd BufDelete * silent! call remove(g:fzf#vim#buffers, expand('<abuf>'))
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user