From b5725c1eec2f596a8e1f6295a4640b2392e5e550 Mon Sep 17 00:00:00 2001 From: Taylor Hedberg Date: Wed, 29 Aug 2012 12:20:39 -0400 Subject: [PATCH] Return to correct window when closing Gblame window Vim does not guarantee persistent window numbers. Instead, windows are numbered according to their position on the screen, with the topmost, leftmost window always having number 1, and the bottommost, rightmost window always having a number equal to the total number of windows currently visible. Crucially, this means that, when a window is closed, windows which come "after" it in the positional order will be renumbered. When fugitive's Gblame window is closed, e.g. by pressing `q`, it attempts to return focus to the window of the blamed buffer. Previously, the number of the window to return to was computed before closing the Gblame window, then the Gblame window was closed, then the blamed buffer's window was focused. However, since windows were often renumbered as soon as the Gblame window was closed, this would frequently cause focus to jump to the window *after* the blamed buffer's window, rather than the intended behavior. This corrects the issue by jumping to the proper return window prior to deleting the Gblame buffer, ensuring that the computed window number is in fact correct at the moment when the focus change occurs. --- plugin/fugitive.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 578124f..3eb81c9 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -1599,8 +1599,8 @@ function! s:Blame(bang,line1,line2,count,args) abort if exists('+relativenumber') setlocal norelativenumber endif - nnoremap q :exe substitute('bdelete'.bufwinnr(b:fugitive_blamed_bufnr).' wincmd w','-1','','') - nnoremap gq :exe substitute('bdelete'.bufwinnr(b:fugitive_blamed_bufnr).' wincmd wif expand("%:p") =~# "^fugitive:[\\/][\\/]"Geditendif','-1','','') + nnoremap q :exe substitute(bufwinnr(b:fugitive_blamed_bufnr).' wincmd w'.bufnr('').'bdelete','^-1','','') + nnoremap gq :exe substitute(bufwinnr(b:fugitive_blamed_bufnr).' wincmd w'.bufnr('').'bdeleteif expand("%:p") =~# "^fugitive:[\\/][\\/]"Geditendif','^-1','','') nnoremap :exe BlameJump('') nnoremap - :exe BlameJump('') nnoremap P :exe BlameJump('^'.v:count1)