commit 8edc9cd0060646cd00de2425178cf82acfccae9e (tree)
parent 382c0a54054467e72840a09484c2b79c6ad13c46
Author: Tim Pope <code@tpope.net>
Date: Fri, 27 Jul 2018 00:35:27 -0400
Work around janky autocommands when returning to diffed window
Closes https://github.com/tpope/vim-fugitive/issues/1065
Diffstat:
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
@@ -2116,6 +2116,7 @@ function! s:Diff(vert,keepfocus,...) abort
endif
let vert = empty(a:vert) ? s:diff_modifier(2) : a:vert
let commit = s:DirCommitFile(@%)[1]
+ let back = exists('*win_getid') ? 'call win_gotoid(' . win_getid() . ')' : 'wincmd p'
if exists(':DiffGitCached')
return 'DiffGitCached'
elseif (empty(args) || args[0] ==# ':') && commit =~# '^[0-1]\=$' && !empty(s:TreeChomp('ls-files', '--unmerged', '--', s:Relative('')))
@@ -2125,12 +2126,12 @@ function! s:Diff(vert,keepfocus,...) abort
execute 'nnoremap <buffer> <silent> dp :diffput '.nr.'<Bar>diffupdate<CR>'
let nr2 = bufnr('')
call s:diffthis()
- wincmd p
+ exe back
execute 'rightbelow '.vert.'split' s:fnameescape(s:Generate(s:Relative(':3:')))
execute 'nnoremap <buffer> <silent> dp :diffput '.nr.'<Bar>diffupdate<CR>'
let nr3 = bufnr('')
call s:diffthis()
- wincmd p
+ exe back
call s:diffthis()
execute 'nnoremap <buffer> <silent> d2o :diffget '.nr2.'<Bar>diffupdate<CR>'
execute 'nnoremap <buffer> <silent> d3o :diffget '.nr3.'<Bar>diffupdate<CR>'
@@ -2175,7 +2176,7 @@ function! s:Diff(vert,keepfocus,...) abort
let w:fugitive_diff_restore = restore
let winnr = winnr()
if getwinvar('#', '&diff')
- wincmd p
+ exe back
if !a:keepfocus
call feedkeys(winnr."\<C-W>w", 'n')
endif