mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
@@ -192,6 +192,36 @@ endfunction
|
||||
function! s:hunk_op(op, ...)
|
||||
let bufnr = bufnr('')
|
||||
|
||||
if &previewwindow
|
||||
if string(a:op) =~ '_stage'
|
||||
" combine hunk-body in preview window with updated hunk-header
|
||||
let hunk_body = getline(1, '$')
|
||||
|
||||
let [removed, added] = [0, 0]
|
||||
for line in hunk_body
|
||||
if line[0] == '-'
|
||||
let removed += 1
|
||||
elseif line[0] == '+'
|
||||
let added += 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
let hunk_header = b:hunk_header
|
||||
" from count
|
||||
let hunk_header[4] = substitute(hunk_header[4], '\(-\d\+\)\(,\d\+\)\?', '\=submatch(1).",".removed', '')
|
||||
" to count
|
||||
let hunk_header[4] = substitute(hunk_header[4], '\(+\d\+\)\(,\d\+\)\?', '\=submatch(1).",".added', '')
|
||||
|
||||
let hunk_diff = join(hunk_header + hunk_body, "\n")."\n"
|
||||
|
||||
wincmd p
|
||||
pclose
|
||||
call s:stage(hunk_diff)
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
if gitgutter#utility#is_active(bufnr)
|
||||
" Get a (synchronous) diff.
|
||||
let [async, g:gitgutter_async] = [g:gitgutter_async, 0]
|
||||
@@ -278,11 +308,12 @@ function! s:preview(hunk_diff)
|
||||
execute 'resize' previewheight
|
||||
endif
|
||||
|
||||
let b:hunk_header = header
|
||||
|
||||
setlocal noreadonly modifiable filetype=diff buftype=nofile bufhidden=delete noswapfile
|
||||
execute "%delete_"
|
||||
call setline(1, body)
|
||||
normal! gg
|
||||
setlocal readonly nomodifiable
|
||||
|
||||
noautocmd wincmd p
|
||||
endfunction
|
||||
@@ -340,11 +371,6 @@ function! s:adjust_hunk_summary(hunk_diff) abort
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:discard_header(hunk_diff)
|
||||
return join(split(a:hunk_diff, '\n', 1)[5:], "\n")
|
||||
endfunction
|
||||
|
||||
|
||||
" Returns the number of lines the current hunk is offset from where it would
|
||||
" be if any changes above it in the file didn't exist.
|
||||
function! s:line_adjustment_for_current_hunk() abort
|
||||
|
||||
Reference in New Issue
Block a user