Skip to content

fix(diff): preserve spaces in word-diff highlights and render without chroma - #17

Merged
jfyne merged 1 commit into
masterfrom
worktree-fix-diff-highlighting
Apr 13, 2026
Merged

fix(diff): preserve spaces in word-diff highlights and render without chroma#17
jfyne merged 1 commit into
masterfrom
worktree-fix-diff-highlighting

Conversation

@jfyne

@jfyne jfyne commented Apr 13, 2026

Copy link
Copy Markdown
Owner

Whats changed

Adds an escapeWordToken helper in internal/app/worddiff.go that converts spaces and tabs to   entities when rendering intra-line word-diff highlights, and changes three diff cells in internal/ui/template.html to gate intra-line HTML on the presence of .HTML instead of the RenderFile flag.

Risk Profile

Signal Value Risk
Size 18 LOC (+14, -4) Low
Files 2 files across 2 directories Low
Sensitive paths none Normal
Test coverage 0 test files / 2 production files Poor
Type Bug-fix Elevated

Overall: CRITICAL — no test coverage drives the floor to High, and the bug-fix type as a second non-low signal escalates to Critical per the algorithm; in practice this is an 18-LOC visual-rendering fix and reviewers should weight the test-coverage and type signals against the small change size.

Suggested Review Order

# File What it does Link
1 worddiff.go Adds escapeWordToken and switches renderIntraLineHTML to use it when escaping word tokens for both old and new side buffers. view
2 template.html Changes three code-text divs (split-view left, split-view right, unified view) so intra-line HTML is rendered whenever .HTML is non-empty rather than only when RenderFile is true. view

… chroma

Word-diff intra-line highlighting was injecting raw spaces into HTML that
otherwise contained   entities from chroma's whitespace normalization,
causing spaces to visually collapse inside highlight spans. Escape word
tokens with   for spaces and tabs to match chroma's output.

The template also gated intra-line diff HTML behind RenderFile, silently
discarding word-diff output when syntax highlighting was disabled. Switch
the guard to check for HTML presence directly so word-diff renders in both
modes while context lines still fall back to plain text.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jfyne
jfyne marked this pull request as ready for review April 13, 2026 09:33
@jfyne
jfyne merged commit 37021fd into master Apr 13, 2026
1 check passed
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