diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 30d2236..c776502 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -1488,9 +1488,9 @@ function! s:Blame(bang,line1,line2,count,args) abort nnoremap :exe BlameJump('') nnoremap P :exe BlameJump('^'.v:count1) nnoremap ~ :exe BlameJump('~'.v:count1) - nnoremap i :exe "exe 'norm q'".Edit("edit", 0, matchstr(getline('.'),'\x\+')) - nnoremap o :exe Edit((&splitbelow ? "botright" : "topleft")." split", 0, matchstr(getline('.'),'\x\+')) - nnoremap O :exe Edit("tabedit", 0, matchstr(getline('.'),'\x\+')) + nnoremap i :exe BlameCommit("exe 'norm q'edit") + nnoremap o :exe BlameCommit((&splitbelow ? "botright" : "topleft")." split") + nnoremap O :exe BlameCommit("tabedit") redraw syncbind endif @@ -1505,6 +1505,47 @@ function! s:Blame(bang,line1,line2,count,args) abort endtry endfunction +function! s:BlameCommit(cmd) abort + let cmd = s:Edit(a:cmd, 0, matchstr(getline('.'),'\x\+')) + if cmd =~# '^echoerr' + return cmd + endif + let lnum = matchstr(getline('.'),' \zs\d\+\ze\s\+[([:digit:]]') + let path = matchstr(getline('.'),'^\^\=\x\+\s\+\zs.\{-\}\ze\s*\d\+ ') + if path ==# '' + let path = s:buffer(b:fugitive_blamed_bufnr).path() + endif + execute cmd + if search('^diff .* b/\M'.escape(path,'\').'$','W') + call search('^+++') + let head = line('.') + while search('^@@ \|^diff ') && getline('.') =~# '^@@ ' + let top = +matchstr(getline('.'),' +\zs\d\+') + let len = +matchstr(getline('.'),' +\d\+,\zs\d\+') + if lnum >= top && lnum <= top + len + let offset = lnum - top + if &scrolloff + + + normal! zt + else + normal! zt + + + endif + while offset > 0 && line('.') < line('$') + + + if getline('.') =~# '^[ +]' + let offset -= 1 + endif + endwhile + return '' + endif + endwhile + execute head + normal! zt + endif + return '' +endfunction + function! s:BlameJump(suffix) abort let commit = matchstr(getline('.'),'^\^\=\zs\x\+') if commit =~# '^0\+$'