diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index 8f6582d3b..4a5c75ede 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -30,9 +30,17 @@ class EditBlockCoder(Coder): path, original, updated = edit full_path = self.abs_root_path(path) content = self.io.read_text(full_path) - content = do_replace(full_path, content, original, updated, self.fence) - if content: - self.io.write_text(full_path, content) + new_content = do_replace(full_path, content, original, updated, self.fence) + if not new_content: + # try patching any of the other files in the chat + for full_path in self.abs_fnames: + content = self.io.read_text(full_path) + new_content = do_replace(full_path, content, original, updated, self.fence) + if new_content: + break + + if new_content: + self.io.write_text(full_path, new_content) passed.append(edit) else: failed.append(edit)