Repository navigation
fix(edit): keep a file's own line endings - #66
Merged
Merged
Conversation
read_text/write_text translate line endings by platform, so one edit turned an LF file into CRLF on Windows and a CRLF file into LF on Linux. Read with newline="", match on LF text as before, and write the file's own ending back. A one-line edit leaves every other byte as it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # README.md # README_CN.md # article/00-index.md # article/00-index_EN.md # corecoder/tools/edit.py # pyproject.toml
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #60. Closes #59.
This carries @goranai's original line-ending fix and its commit history onto current main. The original PR branch had been deleted and the PR was dirty. The implementation is the same; the merge preserves main's undo snapshot recording after the line-ending-preserving write.
edit_fileread and wrote withread_text/write_text. Those translate line endings by platform, so one edit rewrote every line ending in the file.Now it reads with
newline="". It matches on LF text, the same text as before, which is also whatread_fileshows.old_stringornew_string) is applied to the file as read. Every other byte stays as it was, mixed endings included.os.linesep).\r\ninold_stringornew_stringis read as\n. A CRLFold_stringnow matches, and a CRLFnew_stringis no longer written as\r\r\non Windows.Behavior changes, all of them:
old_stringwith\r\nused to give "not found". Now it matches the text as LF. The uniqueness check is unchanged.Tests:
old_string, LF kept with a multi-linenew_string, and a one-line edit leaving mixed endings alone. On main on Windows all three fail. With the fix they pass.new_stringheld\r\nand main wrote\r\r\n. A file with one line ending style keeps it. A one-line edit changes no byte outside the replaced text. 58 and 66 edits that main refused now apply. In the second run I checked them: each had\r\ninold_string.ee56c0f92b33c8dcb55aed871ffda8e805790e1a; its result is tracked separately and is not assumed from local runs.The original #60 validation was performed with Claude Opus 5.5.