Skip to content

fix(ui): normalize line endings in session file diff stats#3082

Open
CnsMaple wants to merge 1 commit into
charmbracelet:mainfrom
CnsMaple:fix/modified-file-line-endings
Open

fix(ui): normalize line endings in session file diff stats#3082
CnsMaple wants to merge 1 commit into
charmbracelet:mainfrom
CnsMaple:fix/modified-file-line-endings

Conversation

@CnsMaple

@CnsMaple CnsMaple commented Jun 5, 2026

Copy link
Copy Markdown

Summary

  • Normalize CRLF/LF on both sides of the session file diff so historical versions with mismatched line endings don't inflate the stats.
  • Add a regression test covering the CRLF↔LF mismatch.

Problem

The sidebar's "Modified Files" list computes additions/deletions by diffing the first and last versions of a file stored in history (internal/ui/model/session.go:139). The two versions can carry different line endings:

  • Files first written via the edit tool preserve the original line endings (CRLF on Windows).
  • Files later overwritten via the write tool store whatever the LLM emitted, which is almost always LF.

When the diff runs, every line is reported as changed because the trailing \r is missing/present. A 1000-line file gaining 1 line shows +1001 -1000 instead of +1 -0.

Fix

Normalize both sides to LF with fsext.ToUnixLineEndings before calling diff.GenerateDiff. This is the same helper the edit/multiedit tools already use internally for diff computation.

Test plan

  • go test ./internal/ui/model/ -run TestLoadSessionFilesNormalizesLineEndings passes
  • go test ./internal/ui/model/ -run TestFileList still passes
  • go build ./...

💘 Generated with Crush

The sidebar's modified-files diff stats are computed by diffing the first
and last versions of a file stored in history. When a file was first
written with one set of line endings (e.g. CRLF, preserved by the edit
tool from a Windows editor) and later overwritten with different line
endings (e.g. LF, typical for LLM-generated content written by the write
tool), every line in the file was reported as changed. A 1000-line file
gained 1 line would show "+1001 -1000" instead of "+1 -0".

Normalize both sides to LF before calling diff.GenerateDiff so the stats
reflect the real textual delta. A regression test covers the
CRLF-vs-LF mismatch and the identical-content case.

💘 Generated with Crush

Assisted-by: Crush:MiniMax-M3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant