Skip to content

fix(editor): preserve file line endings - #3142

Merged
bajrangCoder merged 4 commits into
Acode-Foundation:mainfrom
sanketpatel32:devin/1796128823-fix-eol-state
Dec 2, 2026
Merged

bajrangCoder merged 4 commits into
Acode-Foundation:mainfrom
sanketpatel32:devin/1796128823-fix-eol-state

Conversation

@sanketpatel32

@sanketpatel32 sanketpatel32 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #3086.

Track end-of-line style as explicit EditorFile state instead of inferring it from CodeMirror document lines after normalization. The raw file text is detected before creating the EditorState; EOL mismatches participate in dirty tracking; saving uses doc.sliceString(..., "\r\n" | "\n") so CRLF files remain CRLF and toggling LF to CRLF writes .

Also persist the current/saved EOL state across session restore and resynchronize it when a clean file is reloaded after an external change. Follow-up handling now covers write-time EOL races, legacy sessions with missing EOL metadata, autosave for EOL-only changes, and EOL-only external changes when a provider has no modification time. Explicit EOL choices remain dirty while legacy metadata is unresolved, and asynchronous file checks do not adopt stale read results after a user change.

Tests

  • npm run check (Biome lint/format)
  • npm run typecheck
  • npm test — 1215 tests passed

@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5RetriggerView in Greptile

[Medium impact] The changes affect editor file loading, saving, session restore, and external-file checks.

The PR still needs to mark an explicit selection of the displayed EOL as unsaved when the saved style is unknown.

Findings

  1. P1 Legacy files lose EOL choices ▶

Summary

The PR tracks line endings separately from CodeMirror text so saving can preserve CRLF files.

  • The editor keeps each file’s line-ending style when it saves.
  • Clean open files pick up line-ending changes from disk.

Reviews (3) · Last reviewed commit: "fix: preserve pending EOL choices" · Reviewed by Greptile

Comment thread src/lib/editorFile.js Resolved
Comment thread src/lib/editorFile.js Resolved
Comment thread src/lib/editorFile.js Resolved
Comment thread src/lib/checkFiles.js Resolved
Comment thread src/lib/editorFile.js Outdated
hasUnsavedChanges() {
if (this.type !== "editor") return false;
const currentDoc = this.#rawSession?.doc;
const eolChanged = this.#savedEol !== null && this.#eol !== this.#savedEol;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Legacy files lose EOL choices

A legacy file restored from cache keeps savedEol as null. This condition then ignores an explicit line-ending change and leaves isUnsaved false. Autosave skips the file, Save All excludes it, and closing drops the choice without warning.

Treat an explicit choice as unsaved while the saved style is unknown, then resolve that style before saving.

Knowledge Base Used: Workspace file sessions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in ceb88d9. An explicit EOL change now counts as unsaved while the legacy saved style is unknown, so autosave, Save All, and close handling include it; the unknown style is still resolved from disk before writing. npm run check, npm run typecheck, and npm test pass (1215 tests).

Comment thread src/lib/checkFiles.js Resolved
@bajrangCoder

This comment was marked as outdated.

bajrangCoder added a commit that referenced this pull request Dec 2, 2026
…state

fix(editor): preserve file line endings
@bajrangCoder
bajrangCoder merged commit ceb88d9 into Acode-Foundation:main Dec 2, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in The Code Board - Acode Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Line ending switch does nothing and CRLF files are saved as LF

3 participants