mirror of
https://github.com/junegunn/fzf.vim.git
synced 2026-01-21 10:32:15 +08:00
[[B]Commits] Allow tracking changes in the line range
Thanks to @anhpt379 Close #898 Close #1288
This commit is contained in:
@@ -1201,7 +1201,7 @@ function! s:commits_sink(lines)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:commits(buffer_local, args)
|
||||
function! s:commits(range, buffer_local, args)
|
||||
let s:git_root = s:get_git_root()
|
||||
if empty(s:git_root)
|
||||
return s:warn('Not in git repository')
|
||||
@@ -1215,16 +1215,19 @@ function! s:commits(buffer_local, args)
|
||||
let managed = !v:shell_error
|
||||
endif
|
||||
|
||||
if a:buffer_local
|
||||
if len(a:range) || a:buffer_local
|
||||
if !managed
|
||||
return s:warn('The current buffer is not in the working tree')
|
||||
endif
|
||||
let source .= ' --follow '.fzf#shellescape(current)
|
||||
let source .= len(a:range)
|
||||
\ ? printf(' -L %d,%d:%s --no-patch', a:range[0], a:range[1], fzf#shellescape(current))
|
||||
\ : (' --follow '.fzf#shellescape(current))
|
||||
let command = 'BCommits'
|
||||
else
|
||||
let source .= ' --graph'
|
||||
let command = 'Commits'
|
||||
endif
|
||||
|
||||
let command = a:buffer_local ? 'BCommits' : 'Commits'
|
||||
let expect_keys = join(keys(get(g:, 'fzf_action', s:default_action)), ',')
|
||||
let options = {
|
||||
\ 'source': source,
|
||||
@@ -1249,12 +1252,26 @@ function! s:commits(buffer_local, args)
|
||||
return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, a:args)
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#commits(...)
|
||||
return s:commits(0, a:000)
|
||||
" Heuristically determine if the user specified a range
|
||||
function! s:given_range(line1, line2)
|
||||
" 1. From visual mode
|
||||
" :'<,'>Commits
|
||||
" 2. From command-line
|
||||
" :10,20Commits
|
||||
if a:line1 == line("'<") && a:line2 == line("'>") ||
|
||||
\ (a:line1 != 1 || a:line2 != line('$'))
|
||||
return [a:line1, a:line2]
|
||||
endif
|
||||
|
||||
return []
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#buffer_commits(...)
|
||||
return s:commits(1, a:000)
|
||||
function! fzf#vim#commits(...) range
|
||||
return s:commits(s:given_range(a:firstline, a:lastline), 0, a:000)
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#buffer_commits(...) range
|
||||
return s:commits(s:given_range(a:firstline, a:lastline), 1, a:000)
|
||||
endfunction
|
||||
|
||||
" ------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user