Repository navigation
fix(editor): preserve file line endings - #3142
bajrangCoder merged 4 commits into
Conversation
Confidence Score: 4/5
[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
SummaryThe PR tracks line endings separately from CodeMirror text so saving can preserve CRLF files.
Reviews (3) · Last reviewed commit: "fix: preserve pending EOL choices" · Reviewed by Greptile |
| hasUnsavedChanges() { | ||
| if (this.type !== "editor") return false; | ||
| const currentDoc = this.#rawSession?.doc; | ||
| const eolChanged = this.#savedEol !== null && this.#eol !== this.#savedEol; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
This comment was marked as outdated.
This comment was marked as outdated.
…state fix(editor): preserve file line endings
Summary
Fixes #3086.
Track end-of-line style as explicit
EditorFilestate instead of inferring it from CodeMirror document lines after normalization. The raw file text is detected before creating theEditorState; EOL mismatches participate in dirty tracking; saving usesdoc.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 typechecknpm test— 1215 tests passed