File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -702,12 +702,18 @@ def _replace_at(
702702 if isinstance (value , Table ):
703703 # Insert a cosmetic new line for tables if:
704704 # - it does not have it yet OR is not followed by one
705- # - it is not the last item
705+ # - it is not the last item, or
706+ # - The table being replaced has a newline
706707 last , _ = self ._previous_item_with_index ()
707708 idx = last if idx < 0 else idx
708709 has_ws = ends_with_whitespace (value )
710+ replace_has_ws = (
711+ isinstance (v , Table )
712+ and v .value .body
713+ and isinstance (v .value .body [- 1 ][1 ], Whitespace )
714+ )
709715 next_ws = idx < last and isinstance (self ._body [idx + 1 ][1 ], Whitespace )
710- if idx < last and not (next_ws or has_ws ):
716+ if ( idx < last or replace_has_ws ) and not (next_ws or has_ws ):
711717 value .append (None , Whitespace ("\n " ))
712718
713719 dict .__setitem__ (self , new_key .key , value .value )
You can’t perform that action at this time.
0 commit comments