diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index b03a8a0..bb4886e 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -142,14 +142,22 @@ function! s:Mods(mods, ...) abort let mods = substitute(a:mods, '\C', '', '') 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 =~# '\' ? &winfixheight : &winfixwidth) + let default = 'Edge' + else + let default = '' + endif + endif + if default ==# 'Edge' if mods =~# '\' ? &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('')) @@ -3346,7 +3359,8 @@ function! s:RunEdit(state, tmp, job) abort let noequalalways = 1 setglobal equalalways endif - exe substitute(a:state.mods, '\', '-tab', 'g') 'keepalt split' s:fnameescape(file) + let mods = s:Mods(a:state.mods, 'SpanOrigin') + exe substitute(mods, '\', '-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()