Work around janky autocommands when returning to diffed window

Closes https://github.com/tpope/vim-fugitive/issues/1065
This commit is contained in:
Tim Pope 2018-07-27 00:35:27 -04:00
parent 382c0a5405
commit 8edc9cd006

View File

@ -2116,6 +2116,7 @@ function! s:Diff(vert,keepfocus,...) abort
endif endif
let vert = empty(a:vert) ? s:diff_modifier(2) : a:vert let vert = empty(a:vert) ? s:diff_modifier(2) : a:vert
let commit = s:DirCommitFile(@%)[1] let commit = s:DirCommitFile(@%)[1]
let back = exists('*win_getid') ? 'call win_gotoid(' . win_getid() . ')' : 'wincmd p'
if exists(':DiffGitCached') if exists(':DiffGitCached')
return 'DiffGitCached' return 'DiffGitCached'
elseif (empty(args) || args[0] ==# ':') && commit =~# '^[0-1]\=$' && !empty(s:TreeChomp('ls-files', '--unmerged', '--', s:Relative(''))) 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>' execute 'nnoremap <buffer> <silent> dp :diffput '.nr.'<Bar>diffupdate<CR>'
let nr2 = bufnr('') let nr2 = bufnr('')
call s:diffthis() call s:diffthis()
wincmd p exe back
execute 'rightbelow '.vert.'split' s:fnameescape(s:Generate(s:Relative(':3:'))) execute 'rightbelow '.vert.'split' s:fnameescape(s:Generate(s:Relative(':3:')))
execute 'nnoremap <buffer> <silent> dp :diffput '.nr.'<Bar>diffupdate<CR>' execute 'nnoremap <buffer> <silent> dp :diffput '.nr.'<Bar>diffupdate<CR>'
let nr3 = bufnr('') let nr3 = bufnr('')
call s:diffthis() call s:diffthis()
wincmd p exe back
call s:diffthis() call s:diffthis()
execute 'nnoremap <buffer> <silent> d2o :diffget '.nr2.'<Bar>diffupdate<CR>' execute 'nnoremap <buffer> <silent> d2o :diffget '.nr2.'<Bar>diffupdate<CR>'
execute 'nnoremap <buffer> <silent> d3o :diffget '.nr3.'<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 w:fugitive_diff_restore = restore
let winnr = winnr() let winnr = winnr()
if getwinvar('#', '&diff') if getwinvar('#', '&diff')
wincmd p exe back
if !a:keepfocus if !a:keepfocus
call feedkeys(winnr."\<C-W>w", 'n') call feedkeys(winnr."\<C-W>w", 'n')
endif endif