mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-12 05:13:53 -05:00
Avoid narrow :Git subcommand splits in blame windows
If commit maps are to made available in blame buffers, then the existing behavior of editing the commit message in a horizontal split of a narrow window isn't going to cut it. My ideal solution would be to create a split that spans both the blame buffer and the original file, but I don't think there's a practical way to do that, so I've instead settled for using :topleft/:botright instead, as appropriate. The other natural solution would be to switch to the original file and split there, but that means we'd end up with a scroll-bound window with a mismatched height, which behaves exactly as poorly as you would expect. Furthermore, I've made the decision to extend this behavior to paginated output windows (e.g., `:Git log`), but *not* to other window creation commands like :Gsplit. References: https://github.com/tpope/vim-fugitive/issues/2035
This commit is contained in:
@@ -142,14 +142,22 @@ function! s:Mods(mods, ...) abort
|
||||
let mods = substitute(a:mods, '\C<mods>', '', '')
|
||||
let mods = mods =~# '\S$' ? mods . ' ' : mods
|
||||
if a:0 && mods !~# '\<\%(aboveleft\|belowright\|leftabove\|rightbelow\|topleft\|botright\|tab\)\>'
|
||||
if a:1 ==# 'Edge'
|
||||
let default = a:1
|
||||
if default ==# 'SpanOrigin'
|
||||
if s:OriginBufnr() > 0 && (mods =~# '\<vertical\>' ? &winfixheight : &winfixwidth)
|
||||
let default = 'Edge'
|
||||
else
|
||||
let default = ''
|
||||
endif
|
||||
endif
|
||||
if default ==# 'Edge'
|
||||
if mods =~# '\<vertical\>' ? &splitright : &splitbelow
|
||||
let mods = 'botright ' . mods
|
||||
else
|
||||
let mods = 'topleft ' . mods
|
||||
endif
|
||||
else
|
||||
let mods = a:1 . ' ' . mods
|
||||
let mods = default . ' ' . mods
|
||||
endif
|
||||
endif
|
||||
return substitute(mods, '\s\+', ' ', 'g')
|
||||
@@ -3294,6 +3302,11 @@ function! s:TempDelete(file) abort
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! s:OriginBufnr(...) abort
|
||||
let state = s:TempState(a:0 ? a:1 : bufnr(''))
|
||||
return get(state, 'origin_bufnr', -1)
|
||||
endfunction
|
||||
|
||||
augroup fugitive_temp
|
||||
autocmd!
|
||||
autocmd BufReadPre * exe s:TempReadPre( +expand('<abuf>'))
|
||||
@@ -3346,7 +3359,8 @@ function! s:RunEdit(state, tmp, job) abort
|
||||
let noequalalways = 1
|
||||
setglobal equalalways
|
||||
endif
|
||||
exe substitute(a:state.mods, '\<tab\>', '-tab', 'g') 'keepalt split' s:fnameescape(file)
|
||||
let mods = s:Mods(a:state.mods, 'SpanOrigin')
|
||||
exe substitute(mods, '\<tab\>', '-tab', 'g') 'keepalt split' s:fnameescape(file)
|
||||
finally
|
||||
if exists('l:noequalalways')
|
||||
setglobal noequalalways
|
||||
@@ -3807,9 +3821,9 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg, ...) abort
|
||||
if pager is# 2 && a:bang && a:line2 >= 0
|
||||
let [do_edit, after_edit] = s:ReadPrepare(a:line1, a:line2, a:range, a:mods)
|
||||
elseif pager is# 2 && a:bang
|
||||
let do_edit = s:Mods(a:mods) . 'pedit'
|
||||
let do_edit = s:Mods(a:mods, 'SpanOrigin') . 'pedit'
|
||||
elseif !curwin
|
||||
let do_edit = s:Mods(a:mods) . 'split'
|
||||
let do_edit = s:Mods(a:mods, 'SpanOrigin') . 'split'
|
||||
else
|
||||
let do_edit = s:Mods(a:mods) . 'edit'
|
||||
call s:BlurStatus()
|
||||
|
||||
Reference in New Issue
Block a user