From e60a332fda3a46605596509efafc623e88fafc38 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 3 Aug 2023 14:59:59 -0300 Subject: [PATCH] go for the full line match first --- aider/coders/editblock_coder.py | 7 ++++--- tests/test_editblock.py | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index a9c4ace1e..883f5c109 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -151,13 +151,14 @@ def replace_most_similar_chunk(whole, part, replace): part_lines = part.splitlines(keepends=True) replace_lines = replace.splitlines(keepends=True) + if part_lines in whole_lines: + updated_lines = whole_lines.replace(part_lines, replace_lines) + return updated_lines + res = replace_part_with_missing_leading_whitespace(whole_lines, part_lines, replace_lines) if res: return res - if part in whole: - return whole.replace(part, replace) - try: res = try_dotdotdots(whole, part, replace) except ValueError: diff --git a/tests/test_editblock.py b/tests/test_editblock.py index d24f2198d..9d38fd7d2 100644 --- a/tests/test_editblock.py +++ b/tests/test_editblock.py @@ -23,9 +23,9 @@ class TestUtils(unittest.TestCase): def test_replace_most_similar_chunk(self): 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.\n" + part = "This is a sample text\n" + replace = "This is a replaced text.\n" + expected_output = "This is a replaced text.\nAnother line of text.\nYet another line.\n" result = eb.replace_most_similar_chunk(whole, part, replace) self.assertEqual(result, expected_output)