fix(diff): scope whitespace entity conversion to changed tokens only - #18
Merged
Conversation
jfyne
marked this pull request as ready for review
April 13, 2026 10:11
Previously, the word-diff fix converted ALL whitespace (including unchanged whitespace in equal tokens) to entities. This caused indentation misalignment when changed lines were compared to surrounding context lines, since equal-token whitespace was rendered with glyphs while context lines used literal tabs/spaces under white-space:pre-wrap. The fix: - Equal tokens keep literal whitespace (spaces and tabs) so they align with context lines in the same diff - Only changed-whitespace tokens inside intra-add/intra-del spans use entities (to prevent browser collapse at the span boundary) - Added comprehensive tests covering the no-chroma (RenderFile=false) case and whitespace rendering correctness
jfyne
force-pushed
the
worktree-fix-diff-highlighting
branch
from
April 13, 2026 10:13
84b735e to
c3aadbf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Whats changed
Scopes the word-diff
conversion so that only changed-whitespace tokens insideintra-add/intra-delspans emit entities while equal tokens keep literal whitespace, and adds tests ininternal/app/worddiff_test.goandinternal/app/http_render_test.gocovering the no-chroma render path and whitespace rendering.Risk Profile
Overall: HIGH — bug-fix Type and Medium Size are both at level 2, which escalates the Medium floor one level to High; good test coverage and no sensitive paths keep it from going higher.
Suggested Review Order
worddiff.gohtml.EscapeString(literal whitespace) while keepingescapeWordToken( for spaces/tabs) forwordDelete/wordInserttokens inside intra-line spans.worddiff_test.gotokenizeWords,diffWordTokens, andrenderIntraLineHTML, including whitespace-preservation cases where equal tokens keep literal tabs/spaces and only changed tokens emit .http_render_test.gorenderReviewHTMLwithRenderFile=false(no chroma), confirming theme class, comment form autofocus, and word-diff HTML presence in the rendered page.