@@ -270,13 +270,14 @@ fn push_wrapped_diff_line(
270
270
271
271
// Reserve a fixed number of spaces after the line number so that content starts
272
272
// at a consistent column. The sign ("+"/"-") is rendered as part of the content
273
- // with the same background as the edit, not as a separate dimmed column.
273
+ // and colored with the same foreground as the edited text, not as a separate
274
+ // dimmed column.
274
275
let gap_after_ln = SPACES_AFTER_LINE_NUMBER . saturating_sub ( ln_str. len ( ) ) ;
275
276
let first_prefix_cols = indent. len ( ) + ln_str. len ( ) + gap_after_ln;
276
277
let cont_prefix_cols = indent. len ( ) + ln_str. len ( ) + gap_after_ln;
277
278
278
279
let mut first = true ;
279
- let ( sign_opt, bg_style ) = match kind {
280
+ let ( sign_opt, line_style ) = match kind {
280
281
DiffLineType :: Insert => ( Some ( '+' ) , Some ( style_add ( ) ) ) ,
281
282
DiffLineType :: Delete => ( Some ( '-' ) , Some ( style_del ( ) ) ) ,
282
283
DiffLineType :: Context => ( None , None ) ,
@@ -307,30 +308,38 @@ fn push_wrapped_diff_line(
307
308
spans. push ( RtSpan :: raw ( " " . repeat ( gap_after_ln) ) ) ;
308
309
309
310
// Prefix the content with the sign if it is an insertion or deletion, and color
310
- // the sign with the same background as the edited text.
311
+ // the sign and content with the same foreground as the edited text.
311
312
let display_chunk = match sign_opt {
312
313
Some ( sign_char) => format ! ( "{sign_char}{chunk}" ) ,
313
314
None => chunk. to_string ( ) ,
314
315
} ;
315
316
316
- let content_span = match bg_style {
317
+ let content_span = match line_style {
317
318
Some ( style) => RtSpan :: styled ( display_chunk, style) ,
318
319
None => RtSpan :: raw ( display_chunk) ,
319
320
} ;
320
321
spans. push ( content_span) ;
321
- lines. push ( RtLine :: from ( spans) ) ;
322
+ let mut line = RtLine :: from ( spans) ;
323
+ if let Some ( style) = line_style {
324
+ line. style = line. style . patch ( style) ;
325
+ }
326
+ lines. push ( line) ;
322
327
first = false ;
323
328
} else {
324
329
let hang_prefix = format ! (
325
330
"{indent}{}{}" ,
326
331
" " . repeat( ln_str. len( ) ) ,
327
332
" " . repeat( gap_after_ln)
328
333
) ;
329
- let content_span = match bg_style {
334
+ let content_span = match line_style {
330
335
Some ( style) => RtSpan :: styled ( chunk. to_string ( ) , style) ,
331
336
None => RtSpan :: raw ( chunk. to_string ( ) ) ,
332
337
} ;
333
- lines. push ( RtLine :: from ( vec ! [ RtSpan :: raw( hang_prefix) , content_span] ) ) ;
338
+ let mut line = RtLine :: from ( vec ! [ RtSpan :: raw( hang_prefix) , content_span] ) ;
339
+ if let Some ( style) = line_style {
340
+ line. style = line. style . patch ( style) ;
341
+ }
342
+ lines. push ( line) ;
334
343
}
335
344
}
336
345
lines
@@ -341,11 +350,11 @@ fn style_dim() -> Style {
341
350
}
342
351
343
352
fn style_add ( ) -> Style {
344
- Style :: default ( ) . bg ( Color :: Green )
353
+ Style :: default ( ) . fg ( Color :: Green )
345
354
}
346
355
347
356
fn style_del ( ) -> Style {
348
- Style :: default ( ) . bg ( Color :: Red )
357
+ Style :: default ( ) . fg ( Color :: Red )
349
358
}
350
359
351
360
#[ allow( clippy:: expect_used) ]
0 commit comments