@@ -63,7 +63,8 @@ export const extract_diff_patches = (clipboard_text: string): DiffPatch[] => {
6363 // Extract patch content starting from the --- line
6464 const patch_lines = lines . slice ( patch_start_index ) . map ( ( line ) => {
6565 if ( line . startsWith ( '--- a/' ) || line . startsWith ( '+++ b/' ) ) {
66- return line . replace ( / \t .* $ / , '' ) // Remove everything after tab
66+ // Remove timestamps and everything after tab
67+ return line . replace ( / \s + \d { 4 } - \d { 2 } - \d { 2 } .* $ / , '' ) . replace ( / \t .* $ / , '' )
6768 }
6869 return line
6970 } )
@@ -180,16 +181,20 @@ export const extract_diff_patches = (clipboard_text: string): DiffPatch[] => {
180181 const final_patch_lines = patch_content . split ( '\n' )
181182 const formatted_patch_lines : string [ ] = [ ]
182183 for ( const patch_line of final_patch_lines ) {
183- // Check if line starts with @@ and has content after it without newline
184- const hunk_match = patch_line . match (
185- / ^ ( @ @ - \d + , \d + \+ \d + , \d + @ @ ) ( .* ) $ /
186- )
187- if ( hunk_match && hunk_match [ 2 ] . trim ( ) != '' ) {
188- // Split hunk header and content onto separate lines
189- formatted_patch_lines . push ( hunk_match [ 1 ] )
190- formatted_patch_lines . push ( hunk_match [ 2 ] )
191- } else {
192- formatted_patch_lines . push ( patch_line )
184+ // Remove timestamps from ---/+++ lines
185+ if ( patch_line . startsWith ( '--- a/' ) || patch_line . startsWith ( '+++ b/' ) ) {
186+ formatted_patch_lines . push ( patch_line . replace ( / \s + \d { 4 } - \d { 2 } - \d { 2 } .* $ / , '' ) )
187+ }
188+ // Handle hunk headers
189+ else {
190+ const hunk_match = patch_line . match ( / ^ ( @ @ - \d + , \d + \+ \d + , \d + @ @ ) ( .* ) $ / )
191+ if ( hunk_match && hunk_match [ 2 ] . trim ( ) != '' ) {
192+ // Split hunk header and content onto separate lines
193+ formatted_patch_lines . push ( hunk_match [ 1 ] )
194+ formatted_patch_lines . push ( hunk_match [ 2 ] )
195+ } else {
196+ formatted_patch_lines . push ( patch_line )
197+ }
193198 }
194199 }
195200 patch_content = formatted_patch_lines . join ( '\n' )
@@ -212,7 +217,7 @@ export const extract_diff_patches = (clipboard_text: string): DiffPatch[] => {
212217
213218 // Extract file path from the +++ line or diff --git line
214219 if ( ! current_file_path ) {
215- const file_path_match = line . match ( / ^ \+ \+ \+ b \/ ( .+ ) $ / )
220+ const file_path_match = line . match ( / ^ \+ \+ \+ b \/ ( .+ ? ) (?: \s + \d { 4 } - \d { 2 } - \d { 2 } . * ) ? $ / )
216221 if ( file_path_match ) {
217222 current_file_path = file_path_match [ 1 ]
218223 } else {
@@ -230,4 +235,4 @@ export const extract_diff_patches = (clipboard_text: string): DiffPatch[] => {
230235
231236 return patches
232237 }
233- }
238+ }
0 commit comments