From 5a3fd35c16932a662b30449b9dbd6b3ad3c871e1 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 9 Jun 2023 14:50:21 -0700 Subject: [PATCH] If all lines in the part start with whitespace, then honor it. --- aider/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aider/utils.py b/aider/utils.py index 53e5a5ae9..3daa2d734 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -64,6 +64,12 @@ def replace_part_with_missing_leading_whitespace(whole, part, replace): part_lines = part.splitlines() replace_lines = replace.splitlines() + # If all lines in the part start with whitespace, then honor it. + # But GPT often outdents the part and replace blocks completely, + # thereby discarding the actual leading whitespace in the file. + if all(pline[0].isspace() for pline in part_lines): + return + for i in range(len(whole_lines) - len(part_lines) + 1): leading_whitespace = "" for j, c in enumerate(whole_lines[i]):