diff --git a/aider/utils.py b/aider/utils.py index 139ce4151..54ecc5b05 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -44,7 +44,10 @@ def replace_most_similar_chunk(whole, part, replace): + replace_lines + whole_lines[most_similar_chunk_end:] ) - modified_whole = "\n".join(modified_whole) + "\n" + modified_whole = "\n".join(modified_whole) + + if whole.endswith("\n"): + modified_whole += "\n" return modified_whole diff --git a/tests/test_utils.py b/tests/test_utils.py index 71b740dba..5c76610c7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -4,10 +4,10 @@ from aider.utils import replace_most_similar_chunk, strip_quoted_wrapping class TestUtils(unittest.TestCase): def test_replace_most_similar_chunk(self): - whole = "This is a sample text.\nAnother line of text.\nYet another line." + whole = "This is a sample text.\nAnother line of text.\nYet another line.\n" part = "This is a sample text" replace = "This is a replaced text." - expected_output = "This is a replaced text.\nAnother line of text.\nYet another line." + expected_output = "This is a replaced text..\nAnother line of text.\nYet another line.\n" result = replace_most_similar_chunk(whole, part, replace) self.assertEqual(result, expected_output)