mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-07 13:14:30 +08:00
Improve :BCommits Preview (#1525)
Reduce the preview of :BCommits to the relevant part, when used with visual selection. Only show the part of the diff that belongs to the selection. That makes it very easy to quickly follow the evolution of a code block.
This commit is contained in:
@@ -1474,14 +1474,22 @@ function! s:commits(range, buffer_local, args)
|
|||||||
|
|
||||||
let args = copy(a:args)
|
let args = copy(a:args)
|
||||||
let log_opts = len(args) && type(args[0]) == type('') ? remove(args, 0) : ''
|
let log_opts = len(args) && type(args[0]) == type('') ? remove(args, 0) : ''
|
||||||
|
let with_preview = !s:is_win && &columns > s:wide
|
||||||
|
|
||||||
if len(a:range) || a:buffer_local
|
if len(a:range) || a:buffer_local
|
||||||
if !managed
|
if !managed
|
||||||
return s:warn('The current buffer is not in the working tree')
|
return s:warn('The current buffer is not in the working tree')
|
||||||
endif
|
endif
|
||||||
let source .= len(a:range)
|
if len(a:range)
|
||||||
\ ? join([printf(' -L %d,%d:%s --no-patch', a:range[0], a:range[1], fzf#shellescape(current)), log_opts])
|
let source .= join([printf(' -L %d,%d:%s --no-patch', a:range[0], a:range[1], fzf#shellescape(current)), log_opts])
|
||||||
\ : join([' --follow', log_opts, fzf#shellescape(current)])
|
if with_preview
|
||||||
|
let previewparams = join([printf('log -L %d,%d:%s', a:range[0], a:range[1], fzf#shellescape(current)), log_opts])
|
||||||
|
let previewfilter = " | awk '/commit {1}/ {flag=1;print;next} /^[^ ]*commit/{flag=0} flag' "
|
||||||
|
let previewcmd = prefix . previewparams .' --color=always '. previewfilter
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let source .= join([' --follow', log_opts, fzf#shellescape(current)])
|
||||||
|
endif
|
||||||
let command = 'BCommits'
|
let command = 'BCommits'
|
||||||
else
|
else
|
||||||
let source .= join([' --graph', log_opts])
|
let source .= join([' --graph', log_opts])
|
||||||
@@ -1503,12 +1511,14 @@ function! s:commits(range, buffer_local, args)
|
|||||||
let options.options[-1] .= ',ctrl-d'
|
let options.options[-1] .= ',ctrl-d'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !s:is_win && &columns > s:wide
|
if with_preview
|
||||||
let suffix = executable('delta') ? '| delta --width $FZF_PREVIEW_COLUMNS' : ''
|
if !len(a:range)
|
||||||
let orderfile = tempname()
|
let orderfile = tempname()
|
||||||
call writefile([current[len(s:git_root)+1:]], orderfile)
|
call writefile([current[len(s:git_root)+1:]], orderfile)
|
||||||
call extend(options.options,
|
let previewcmd = 'echo {} | grep -o "[a-f0-9]\{7,\}" | head -1 | xargs ' . prefix . 'show -O'.fzf#shellescape(orderfile).' --format=format: --color=always '
|
||||||
\ ['--preview', 'echo {} | grep -o "[a-f0-9]\{7,\}" | head -1 | xargs ' . prefix . 'show -O'.fzf#shellescape(orderfile).' --format=format: --color=always ' . suffix])
|
endif
|
||||||
|
let suffix = executable('delta') ? '| delta --width $FZF_PREVIEW_COLUMNS' : ''
|
||||||
|
call extend(options.options, ['--preview', previewcmd . suffix])
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, args)
|
return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, args)
|
||||||
|
|||||||
Reference in New Issue
Block a user