Preserve existing 'scrollbind' arrangement with :Gblame

Closes https://github.com/tpope/vim-fugitive/issues/1449

Closes https://github.com/tpope/vim-fugitive/issues/1327
This commit is contained in:
Tim Pope
2020-02-03 11:01:22 -05:00
parent 9ecd6ebf92
commit 083f3c23cc

View File

@@ -5157,29 +5157,38 @@ function! s:BlameSubcommand(line1, count, range, bang, mods, options) abort
if a:mods =~# '\<tab\>'
silent tabedit %
endif
let bufnr = bufnr('')
let temp_state.bufnr = bufnr
let restore = []
let mods = substitute(a:mods, '\<tab\>', '', 'g')
for winnr in range(winnr('$'),1,-1)
if getwinvar(winnr, '&scrollbind')
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
if exists('+cursorbind') && getwinvar(winnr, '&cursorbind')
endif
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