Skip to content

Commit

Permalink
[[B]Commits] Preserve window view (#1289)
Browse files Browse the repository at this point in the history
In 161da95, [B]Commits were changed to range commands with -range=%, now
Vim jumps to the first line when these two commands are called directly
without specifying range.

This fixes it by saving window view in a temporary variable and
restoring it later. Reference: [1].

[1] https://vi.stackexchange.com/a/6037/33583
  • Loading branch information
Frederick888 authored May 25, 2021
1 parent 161da95 commit e34f6c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions autoload/fzf/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1267,10 +1267,18 @@ function! s:given_range(line1, line2)
endfunction

function! fzf#vim#commits(...) range
if exists('b:fzf_winview')
call winrestview(b:fzf_winview)
unlet b:fzf_winview
endif
return s:commits(s:given_range(a:firstline, a:lastline), 0, a:000)
endfunction

function! fzf#vim#buffer_commits(...) range
if exists('b:fzf_winview')
call winrestview(b:fzf_winview)
unlet b:fzf_winview
endif
return s:commits(s:given_range(a:firstline, a:lastline), 1, a:000)
endfunction

Expand Down
4 changes: 2 additions & 2 deletions plugin/fzf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ call s:defs([
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
\'command! -bar -bang Helptags call fzf#vim#helptags(<bang>0)',
\'command! -bar -bang Windows call fzf#vim#windows(<bang>0)',
\'command! -bar -bang -range=% Commits <line1>,<line2>call fzf#vim#commits(fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
\'command! -bar -bang -range=% BCommits <line1>,<line2>call fzf#vim#buffer_commits(fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
\'command! -bar -bang -range=% Commits let b:fzf_winview = winsaveview() | <line1>,<line2>call fzf#vim#commits(fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
\'command! -bar -bang -range=% BCommits let b:fzf_winview = winsaveview() | <line1>,<line2>call fzf#vim#buffer_commits(fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
\'command! -bar -bang Maps call fzf#vim#maps("n", <bang>0)',
\'command! -bar -bang Filetypes call fzf#vim#filetypes(<bang>0)',
\'command! -bang -nargs=* History call s:history(<q-args>, fzf#vim#with_preview(), <bang>0)'])
Expand Down

0 comments on commit e34f6c1

Please sign in to comment.