diff --git a/plugin/magit.vim b/plugin/magit.vim index 70acdada36d40c6b715dfa2dbb3bc41a2ce0ade6..78d99baf85adf0ff5b8b7c3b8630819b2ea73c6d 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 =~ '^-.*' )