Skip to content

Line Ending Issue for external diff commands#97

Open
debjan wants to merge 1 commit intocolinta:mainfrom
debjan:feature/buffer_line_endings
Open

Line Ending Issue for external diff commands#97
debjan wants to merge 1 commit intocolinta:mainfrom
debjan:feature/buffer_line_endings

Conversation

@debjan
Copy link
Copy Markdown

@debjan debjan commented Apr 4, 2026

Problem

When using "Diff file with Saved" on Windows with CRLF line endings:

  1. The saved file on disk has CRLF (\r\n)
  2. The Sublime buffer (unsaved content) is retrieved with LF (\n) line endings
  3. diff_with_external() writes the temp file with LF line endings
  4. External diff tool shows false differences -- every line appears changed due to line ending mismatch

Root Cause

The prep_content() method normalizes all line endings to LF:

def prep_content(self, ab, file_name, default_name):
    content = ab.splitlines(True)
    content = [line.replace("\r\n", "\n").replace("\r", "\n") for line in content]

This is fine for internal Sublime diffs, but problematic for external diff tools comparing temp files.

Solution

Detect buffer line ending style and apply it when writing temp files for external diff:

  1. get_buffer_line_ending() - Detect buffer line ending
  2. set_line_endings(content, line_ending) - Normalize all line endings in content to specified line ending
  3. Modify diff_with_external() - Apply detected line ending before writing temp files

Fix Status

The fix preserves internal Sublime diff behavior while ensuring external diff tools receive properly line-ending-matched temp files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant