From e34f6c129d39b90db44df1107c8b7dfacfd18946 Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Tue, 25 May 2021 14:30:41 +1000 Subject: [PATCH] [[B]Commits] Preserve window view (#1289) 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 --- autoload/fzf/vim.vim | 8 ++++++++ plugin/fzf.vim | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index 983ef1f..6ae9817 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -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 diff --git a/plugin/fzf.vim b/plugin/fzf.vim index f74c6f6..ac0177b 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -62,8 +62,8 @@ call s:defs([ \'command! -bar -bang Marks call fzf#vim#marks(0)', \'command! -bar -bang Helptags call fzf#vim#helptags(0)', \'command! -bar -bang Windows call fzf#vim#windows(0)', -\'command! -bar -bang -range=% Commits ,call fzf#vim#commits(fzf#vim#with_preview({ "placeholder": "" }), 0)', -\'command! -bar -bang -range=% BCommits ,call fzf#vim#buffer_commits(fzf#vim#with_preview({ "placeholder": "" }), 0)', +\'command! -bar -bang -range=% Commits let b:fzf_winview = winsaveview() | ,call fzf#vim#commits(fzf#vim#with_preview({ "placeholder": "" }), 0)', +\'command! -bar -bang -range=% BCommits let b:fzf_winview = winsaveview() | ,call fzf#vim#buffer_commits(fzf#vim#with_preview({ "placeholder": "" }), 0)', \'command! -bar -bang Maps call fzf#vim#maps("n", 0)', \'command! -bar -bang Filetypes call fzf#vim#filetypes(0)', \'command! -bang -nargs=* History call s:history(, fzf#vim#with_preview(), 0)'])