Take a diff line's background from git's own color, once#2166
Open
igrmk wants to merge 1 commit into
Open
Conversation
A diff line's effective background now comes from git's own coloring of the +/- marker (mapped through map-styles), computed once where git's signal is still intact and threaded to both the right-fill and the wrapper -- including through the wrap reflow. The fill, the wrap glyph and padding, blank moved lines, and whitespace-error lines all read this single per-line value instead of reverse-engineering the line's color from the painted cells. Removes the right-fill's last-real-style-section guess (the .rev().filter(s != "\n").next() over the painted sections) -- the one place that inferred a captured line's color from its cells. The single per-line value replaces it and fixes its failure modes: a blank moved line (no non-newline section to read), a whitespace-error highlight stretched across the row, and a content style colliding with whitespace-error-style. Because the fill never inspects a cell, it can no longer be spoofed.
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.
Supersedes #2164 — same bug, but that fix was fragile: it handled the demoed case while other configs broke it again.
Symptom
In side-by-side,
map-stylescan recolor a moved line. Its content gets the new color, but the empty background after it staysminus-/plus-style. Wrap character and padding of wrapped lines could have the same mismatch. A blank moved line loses its color as well.Reproduce on this repo (git config neutralized, color-moved on, delta driven by flags, output cropped to the moved block):
Before
After
The problem
Currently, in side-by-side mode delta guesses the fill color from the already-painted cells. This could be fragile: it seems you can always find a counterexample. E.g. with
map-stylesyou can map a moved line to delta's ownwhitespace-errorstyle. Now the guess can't tell apart. To stop real highlights bleeding into the fill, delta ignores cells styled like whitespace-error — but that also ignores your mapped content, so the background after it staysminus-/plus-styleagain. Stop ignoring them and real highlights smear across the row instead. The blank moved line is the same: git colors only the-marker, which delta strips.The fix
git's
+/-marker colors seem to be the most reliable source of a line's color. Read the line's leading SGR, map it throughmap-styles, store it as the line's style, pass it to the right-fill and the wrapper, and use it instead of reverse-engineering it from cells.One per-line value now handles all four cases:
Why the leading style, not an inner one
git emits a diff line's color at byte 0 — on the marker — and resets at the newline, so it's stateless per line and always at the front. So read the leading SGR, not the first style found anywhere. A later one could be intra-line word/whitespace emphasis (
diff-highlight, trailing-whitespace reverse), not the line's color. A line that doesn't open with a style yields nothing. It seems safe to fall back to minus/plus-style.Fixed as well
Beyond the moved-line symptom, reading the leading SGR makes the fill position-independent. The dropped per-cell guess used a line's last styled span, so an accent that sat last smeared across the row while the same accent mid-line did not. Wherever delta keeps git's color this is now consistent:
rawstyles (--minus-style raw/--plus-style raw):a colored substring — or a whitespace highlight under an uncolored marker
(
color.diff.new = normal) — no longer smears to the edge;a line that opens with no color falls back to minus/plus-style.
diff-highlightand trailing-whitespace emphasis:an inner or last span never drives the fill,
even on a color-moved line whose real color is at the front.
Pinned by
test_line_background_from_git_ignores_non_leading_colorand
test_right_fill_ignores_non_leading_cell_color.Scope / non-goals
inspect-raw-lines); ordinary red/green+/-still becomes delta'sminus-/plus-style.+/-in the foreground; turning that into a background is delta's job: git's color →map-styles→ per-line background.