@@ -412,11 +412,13 @@ fn diff_buffers<'a>(a: &'a Buffer, b: &'a Buffer) -> Vec<DrawCommand<'a>> {
412412 . unwrap_or ( 0 ) ;
413413 last_nonblank_column[ y as usize ] = x as u16 ;
414414 let ( x_abs, y_abs) = a. pos_of ( row_start + x + 1 ) ;
415- updates. push ( DrawCommand :: ClearToEnd {
416- x : x_abs,
417- y : y_abs,
418- bg,
419- } ) ;
415+ if x < ( a. area . width as usize ) . saturating_sub ( 1 ) {
416+ updates. push ( DrawCommand :: ClearToEnd {
417+ x : x_abs,
418+ y : y_abs,
419+ bg,
420+ } ) ;
421+ }
420422 }
421423
422424 // Cells invalidated by drawing/replacing preceding multi-width characters:
@@ -570,3 +572,38 @@ impl ModifierDiff {
570572 Ok ( ( ) )
571573 }
572574}
575+
576+ #[ cfg( test) ]
577+ mod tests {
578+ use super :: * ;
579+ use pretty_assertions:: assert_eq;
580+ use ratatui:: layout:: Rect ;
581+
582+ #[ test]
583+ fn diff_buffers_does_not_emit_clear_to_end_for_full_width_row ( ) {
584+ let area = Rect :: new ( 0 , 0 , 3 , 2 ) ;
585+ let previous = Buffer :: empty ( area) ;
586+ let mut next = Buffer :: empty ( area) ;
587+
588+ next. cell_mut ( ( 2 , 0 ) )
589+ . expect ( "cell should exist" )
590+ . set_symbol ( "X" ) ;
591+
592+ let commands = diff_buffers ( & previous, & next) ;
593+
594+ let clear_count = commands
595+ . iter ( )
596+ . filter ( |command| matches ! ( command, DrawCommand :: ClearToEnd { y, .. } if * y == 0 ) )
597+ . count ( ) ;
598+ assert_eq ! (
599+ 0 , clear_count,
600+ "expected diff_buffers not to emit ClearToEnd; commands: {commands:?}" ,
601+ ) ;
602+ assert ! (
603+ commands
604+ . iter( )
605+ . any( |command| matches!( command, DrawCommand :: Put { x: 2 , y: 0 , .. } ) ) ,
606+ "expected diff_buffers to update the final cell; commands: {commands:?}" ,
607+ ) ;
608+ }
609+ }
0 commit comments