@@ -561,6 +561,48 @@ impl<'a> BlockMapWriter<'a> {
561561 ids
562562 }
563563
564+ pub fn replace ( & mut self , mut heights_and_renderers : HashMap < BlockId , ( u8 , RenderBlock ) > ) {
565+ let wrap_snapshot = & * self . 0 . wrap_snapshot . borrow ( ) ;
566+ let buffer = wrap_snapshot. buffer_snapshot ( ) ;
567+ let mut edits = Patch :: default ( ) ;
568+ let mut last_block_buffer_row = None ;
569+
570+ for block in & mut self . 0 . blocks {
571+ if let Some ( ( new_height, render) ) = heights_and_renderers. remove ( & block. id ) {
572+ if block. height != new_height {
573+ let new_block = Block {
574+ id : block. id ,
575+ position : block. position ,
576+ height : new_height,
577+ style : block. style ,
578+ render : Mutex :: new ( render) ,
579+ disposition : block. disposition ,
580+ } ;
581+ * block = Arc :: new ( new_block) ;
582+
583+ let buffer_row = block. position . to_point ( buffer) . row ;
584+ if last_block_buffer_row != Some ( buffer_row) {
585+ last_block_buffer_row = Some ( buffer_row) ;
586+ let wrap_row = wrap_snapshot
587+ . make_wrap_point ( Point :: new ( buffer_row, 0 ) , Bias :: Left )
588+ . row ( ) ;
589+ let start_row =
590+ wrap_snapshot. prev_row_boundary ( WrapPoint :: new ( wrap_row, 0 ) ) ;
591+ let end_row = wrap_snapshot
592+ . next_row_boundary ( WrapPoint :: new ( wrap_row, 0 ) )
593+ . unwrap_or ( wrap_snapshot. max_point ( ) . row ( ) + 1 ) ;
594+ edits. push ( Edit {
595+ old : start_row..end_row,
596+ new : start_row..end_row,
597+ } )
598+ }
599+ }
600+ }
601+ }
602+
603+ self . 0 . sync ( wrap_snapshot, edits) ;
604+ }
605+
564606 pub fn remove ( & mut self , block_ids : HashSet < BlockId > ) {
565607 let wrap_snapshot = & * self . 0 . wrap_snapshot . borrow ( ) ;
566608 let buffer = wrap_snapshot. buffer_snapshot ( ) ;
0 commit comments