mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-12 21:33: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 = substitute(a:mods, '\C<mods>', '', '')
|
||||||
let mods = mods =~# '\S$' ? mods . ' ' : mods
|
let mods = mods =~# '\S$' ? mods . ' ' : mods
|
||||||
if a:0 && mods !~# '\<\%(aboveleft\|belowright\|leftabove\|rightbelow\|topleft\|botright\|tab\)\>'
|
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
|
if mods =~# '\<vertical\>' ? &splitright : &splitbelow
|
||||||
let mods = 'botright ' . mods
|
let mods = 'botright ' . mods
|
||||||
else
|
else
|
||||||
let mods = 'topleft ' . mods
|
let mods = 'topleft ' . mods
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
let mods = a:1 . ' ' . mods
|
let mods = default . ' ' . mods
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
return substitute(mods, '\s\+', ' ', 'g')
|
return substitute(mods, '\s\+', ' ', 'g')
|
||||||
@@ -3294,6 +3302,11 @@ function! s:TempDelete(file) abort
|
|||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:OriginBufnr(...) abort
|
||||||
|
let state = s:TempState(a:0 ? a:1 : bufnr(''))
|
||||||
|
return get(state, 'origin_bufnr', -1)
|
||||||
|
endfunction
|
||||||
|
|
||||||
augroup fugitive_temp
|
augroup fugitive_temp
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufReadPre * exe s:TempReadPre( +expand('<abuf>'))
|
autocmd BufReadPre * exe s:TempReadPre( +expand('<abuf>'))
|
||||||
@@ -3346,7 +3359,8 @@ function! s:RunEdit(state, tmp, job) abort
|
|||||||
let noequalalways = 1
|
let noequalalways = 1
|
||||||
setglobal equalalways
|
setglobal equalalways
|
||||||
endif
|
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
|
finally
|
||||||
if exists('l:noequalalways')
|
if exists('l:noequalalways')
|
||||||
setglobal 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
|
if pager is# 2 && a:bang && a:line2 >= 0
|
||||||
let [do_edit, after_edit] = s:ReadPrepare(a:line1, a:line2, a:range, a:mods)
|
let [do_edit, after_edit] = s:ReadPrepare(a:line1, a:line2, a:range, a:mods)
|
||||||
elseif pager is# 2 && a:bang
|
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
|
elseif !curwin
|
||||||
let do_edit = s:Mods(a:mods) . 'split'
|
let do_edit = s:Mods(a:mods, 'SpanOrigin') . 'split'
|
||||||
else
|
else
|
||||||
let do_edit = s:Mods(a:mods) . 'edit'
|
let do_edit = s:Mods(a:mods) . 'edit'
|
||||||
call s:BlurStatus()
|
call s:BlurStatus()
|
||||||
|
|||||||
Reference in New Issue
Block a user