From 083f3c23ccad22b5d2bdabcbb8a076e8c695686b Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 3 Feb 2020 11:01:22 -0500 Subject: [PATCH] Preserve existing 'scrollbind' arrangement with :Gblame Closes https://github.com/tpope/vim-fugitive/issues/1449 Closes https://github.com/tpope/vim-fugitive/issues/1327 --- autoload/fugitive.vim | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index b6918b3..9115976 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -5157,29 +5157,38 @@ function! s:BlameSubcommand(line1, count, range, bang, mods, options) abort if a:mods =~# '\' silent tabedit % endif + let bufnr = bufnr('') + let temp_state.bufnr = bufnr + let restore = [] let mods = substitute(a:mods, '\', '', 'g') for winnr in range(winnr('$'),1,-1) if getwinvar(winnr, '&scrollbind') - call setwinvar(winnr, '&scrollbind', 0) + if !&l:scrollbind + call setwinvar(winnr, '&scrollbind', 0) + elseif winnr != winnr() && getwinvar(winnr, '&foldenable') + call setwinvar(winnr, '&foldenable', 0) + call add(restore, 'call setwinvar(bufwinnr('.winbufnr(winnr).'),"&foldenable",1)') + endif endif - if exists('+cursorbind') && getwinvar(winnr, '&cursorbind') + if exists('+cursorbind') && !&l:cursorbind && getwinvar(winnr, '&cursorbind') call setwinvar(winnr, '&cursorbind', 0) endif if s:BlameBufnr(winbufnr(winnr)) > 0 execute winbufnr(winnr).'bdelete' endif endfor - let bufnr = bufnr('') - let temp_state.bufnr = bufnr - let restore = 'call setwinvar(bufwinnr('.bufnr.'),"&scrollbind",0)' - if exists('+cursorbind') - let restore .= '|call setwinvar(bufwinnr('.bufnr.'),"&cursorbind",0)' + let restore_winnr = 'bufwinnr(' . bufnr . ')' + if !&l:scrollbind + call add(restore, 'call setwinvar(' . restore_winnr . ',"&scrollbind",0)') + endif + if exists('+cursorbind') && !&l:cursorbind + call add(restore, 'call setwinvar(' . restore_winnr . ',"&cursorbind",0)') endif if &l:wrap - let restore .= '|call setwinvar(bufwinnr('.bufnr.'),"&wrap",1)' + call add(restore, 'call setwinvar(' . restore_winnr . ',"&wrap",1)') endif if &l:foldenable - let restore .= '|call setwinvar(bufwinnr('.bufnr.'),"&foldenable",1)' + call add(restore, 'call setwinvar(' . restore_winnr . ',"&foldenable",1)') endif setlocal scrollbind nowrap nofoldenable if exists('+cursorbind') @@ -5188,7 +5197,7 @@ function! s:BlameSubcommand(line1, count, range, bang, mods, options) abort let top = line('w0') + &scrolloff let current = line('.') exe 'silent keepalt' (a:bang ? s:Mods(mods) . 'split' : s:Mods(mods, 'leftabove') . 'vsplit') s:fnameescape(temp) - let w:fugitive_leave = restore + let w:fugitive_leave = join(restore, '|') execute top normal! zt execute current