From 37f32c0f78ed3187689fcb29c391d60c4141db4f Mon Sep 17 00:00:00 2001 From: Jerome Reybert <jerome.reybert@kalray.eu> Date: Sun, 18 Oct 2015 22:47:53 +0200 Subject: [PATCH] plugin/magit.vim: rework s:mg_create_diff_from_select function --- plugin/magit.vim | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugin/magit.vim b/plugin/magit.vim index 70acdad..78d99ba 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -417,12 +417,14 @@ endfunction " s:mg_create_diff_from_select: craft the diff to apply from a selection " in a chunk " remarks: it works with full lines, and can not span over multiple chunks -" param[in] start_chunk_line,end_chunk_line: limits of the selection +" param[in] start_select_line,end_select_line: limits of the selection " return: List containing the diff to apply, including the chunk header (must " be applied with git apply --recount) -function! s:mg_create_diff_from_select(start_chunk_line, end_chunk_line) - let lines=getline(a:start_chunk_line, a:end_chunk_line) +function! s:mg_create_diff_from_select(start_select_line, end_select_line) let [starthunk,endhunk] = <SID>mg_select_hunk_block() + if ( a:start_select_line < starthunk || a:end_select_line > endhunk ) + throw 'out of hunk selection' + endif let section=<SID>mg_get_section() let filename=<SID>mg_get_filename() let hunks = s:state.get_hunks(section, filename) @@ -433,13 +435,13 @@ function! s:mg_create_diff_from_select(start_chunk_line, end_chunk_line) endif endfor let selection = [] - let visual_selection = getline(a:start_chunk_line, a:end_chunk_line) + let visual_selection = getline(a:start_select_line, a:end_select_line) call add(selection, current_hunk.header) let current_line = starthunk + 1 for hunk_line in current_hunk.lines - if ( current_line >= a:start_chunk_line && current_line <= a:end_chunk_line ) - call add(selection, visual_selection[current_line-a:start_chunk_line]) + if ( current_line >= a:start_select_line && current_line <= a:end_select_line ) + call add(selection, visual_selection[current_line-a:start_select_line]) elseif ( hunk_line =~ '^+.*' ) " just ignore these lines elseif ( hunk_line =~ '^-.*' ) -- GitLab