@@ -145,12 +145,11 @@ function M.write_formatted_data(formatted_data, part_id, start_line)
145145 if is_insertion then
146146 output_window .set_lines (new_lines , target_line , target_line )
147147 else
148- -- Append: temporarily add a separating blank line in-place to avoid an
149- -- O(n) copy, then restore. set_lines is synchronous so this is safe.
148+ -- Append: overlap the last buffer line with our lines
150149 target_line = target_line - 1
151- new_lines [ # new_lines + 1 ] = ' '
152- output_window . set_lines ( new_lines , target_line )
153- new_lines [ # new_lines ] = nil
150+ local append_lines = table.move ( new_lines , 1 , # new_lines , 1 , {})
151+ append_lines [ # append_lines + 1 ] = ' '
152+ output_window . set_lines ( append_lines , target_line )
154153 end
155154
156155 if part_id and formatted_data .actions then
@@ -300,8 +299,8 @@ function M.remove_part(part_id)
300299 return
301300 end
302301 output_window .begin_update ()
303- output_window .clear_extmarks (cached .line_start - 1 , cached .line_end )
304- output_window .set_lines ({}, cached .line_start - 1 , cached .line_end )
302+ output_window .clear_extmarks (cached .line_start - 1 , cached .line_end + 1 )
303+ output_window .set_lines ({}, cached .line_start , cached .line_end + 1 )
305304 output_window .end_update ()
306305 ctx .render_state :remove_part (part_id )
307306end
@@ -362,8 +361,8 @@ function M.remove_message(message_id)
362361 return
363362 end
364363 output_window .begin_update ()
365- output_window .clear_extmarks (cached .line_start - 1 , cached .line_end )
366- output_window .set_lines ({}, cached .line_start - 1 , cached .line_end )
364+ output_window .clear_extmarks (cached .line_start - 1 , cached .line_end + 1 )
365+ output_window .set_lines ({}, cached .line_start , cached .line_end + 1 )
367366 output_window .end_update ()
368367 ctx .render_state :remove_message (message_id )
369368end
0 commit comments