mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 19:43:47 -05:00
Extract methods for clarity.
This commit is contained in:
@@ -134,50 +134,28 @@ function! s:process_hunk(hunk)
|
|||||||
let to_count = a:hunk[3]
|
let to_count = a:hunk[3]
|
||||||
|
|
||||||
if s:is_added(from_count, to_count)
|
if s:is_added(from_count, to_count)
|
||||||
let offset = 0
|
call s:process_added(modifications, from_count, to_count, to_line)
|
||||||
while offset < to_count
|
|
||||||
let line_number = to_line + offset
|
|
||||||
call add(modifications, [line_number, 'added'])
|
|
||||||
let offset += 1
|
|
||||||
endwhile
|
|
||||||
|
|
||||||
elseif s:is_removed(from_count, to_count)
|
elseif s:is_removed(from_count, to_count)
|
||||||
call add(modifications, [to_line, 'removed'])
|
call s:process_removed(modifications, from_count, to_count, to_line)
|
||||||
|
|
||||||
elseif s:is_modified(from_count, to_count)
|
elseif s:is_modified(from_count, to_count)
|
||||||
let offset = 0
|
call s:process_modified(modifications, from_count, to_count, to_line)
|
||||||
while offset < to_count
|
|
||||||
let line_number = to_line + offset
|
|
||||||
call add(modifications, [line_number, 'modified'])
|
|
||||||
let offset += 1
|
|
||||||
endwhile
|
|
||||||
|
|
||||||
elseif s:is_modified_and_added(from_count, to_count)
|
elseif s:is_modified_and_added(from_count, to_count)
|
||||||
let offset = 0
|
call s:process_modified_and_added(modifications, from_count, to_count, to_line)
|
||||||
while offset < from_count
|
|
||||||
let line_number = to_line + offset
|
|
||||||
call add(modifications, [line_number, 'modified'])
|
|
||||||
let offset += 1
|
|
||||||
endwhile
|
|
||||||
while offset < to_count
|
|
||||||
let line_number = to_line + offset
|
|
||||||
call add(modifications, [line_number, 'added'])
|
|
||||||
let offset += 1
|
|
||||||
endwhile
|
|
||||||
|
|
||||||
elseif s:is_modified_and_removed(from_count, to_count)
|
elseif s:is_modified_and_removed(from_count, to_count)
|
||||||
let offset = 0
|
call s:process_modified_and_removed(modifications, from_count, to_count, to_line)
|
||||||
while offset < to_count
|
|
||||||
let line_number = to_line + offset
|
|
||||||
call add(modifications, [line_number, 'modified'])
|
|
||||||
let offset += 1
|
|
||||||
endwhile
|
|
||||||
call add(modifications, [to_line + offset - 1, 'modified_removed'])
|
|
||||||
|
|
||||||
endif
|
endif
|
||||||
return modifications
|
return modifications
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" }}}
|
||||||
|
|
||||||
|
" Diff utility {{{
|
||||||
|
|
||||||
function! s:is_added(from_count, to_count)
|
function! s:is_added(from_count, to_count)
|
||||||
return a:from_count == 0 && a:to_count > 0
|
return a:from_count == 0 && a:to_count > 0
|
||||||
endfunction
|
endfunction
|
||||||
@@ -198,6 +176,52 @@ function! s:is_modified_and_removed(from_count, to_count)
|
|||||||
return a:from_count > 0 && a:to_count > 0 && a:from_count > a:to_count
|
return a:from_count > 0 && a:to_count > 0 && a:from_count > a:to_count
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:process_added(modifications, from_count, to_count, to_line)
|
||||||
|
let offset = 0
|
||||||
|
while offset < a:to_count
|
||||||
|
let line_number = a:to_line + offset
|
||||||
|
call add(a:modifications, [line_number, 'added'])
|
||||||
|
let offset += 1
|
||||||
|
endwhile
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:process_removed(modifications, from_count, to_count, to_line)
|
||||||
|
call add(a:modifications, [a:to_line, 'removed'])
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:process_modified(modifications, from_count, to_count, to_line)
|
||||||
|
let offset = 0
|
||||||
|
while offset < a:to_count
|
||||||
|
let line_number = a:to_line + offset
|
||||||
|
call add(a:modifications, [line_number, 'modified'])
|
||||||
|
let offset += 1
|
||||||
|
endwhile
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:process_modified_and_added(modifications, from_count, to_count, to_line)
|
||||||
|
let offset = 0
|
||||||
|
while offset < a:from_count
|
||||||
|
let line_number = a:to_line + offset
|
||||||
|
call add(a:modifications, [line_number, 'modified'])
|
||||||
|
let offset += 1
|
||||||
|
endwhile
|
||||||
|
while offset < a:to_count
|
||||||
|
let line_number = a:to_line + offset
|
||||||
|
call add(a:modifications, [line_number, 'added'])
|
||||||
|
let offset += 1
|
||||||
|
endwhile
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:process_modified_and_removed(modifications, from_count, to_count, to_line)
|
||||||
|
let offset = 0
|
||||||
|
while offset < a:to_count
|
||||||
|
let line_number = a:to_line + offset
|
||||||
|
call add(a:modifications, [line_number, 'modified'])
|
||||||
|
let offset += 1
|
||||||
|
endwhile
|
||||||
|
call add(a:modifications, [a:to_line + offset - 1, 'modified_removed'])
|
||||||
|
endfunction
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
" Sign processing {{{
|
" Sign processing {{{
|
||||||
|
|||||||
Reference in New Issue
Block a user