Skip to content

Commit 34f2348

Browse files
Geeven SinghCopilot
andcommitted
Paint full visual-line box, eliminating inter-line gaps
The two background renderers used BackgroundGeometryBuilder.GetRectsFromVisualSegment(textView, visualLine, 0, int.MaxValue) to enumerate the text-segment rectangles for each visual line. Those rectangles are sized to the text-segment bounding box, which on some DPI / line-spacing combinations does not cover the full vertical extent of the line box -- leaving a 1-2 px sliver of untinted background between adjacent diff-tinted rows. With the soft tints those slivers were effectively invisible; with the new strong full-line tints they were obvious horizontal "stripes" between every row in a delete or insert block. Switch both renderers to paint a single rectangle per visual line at (0, VisualTop - ScrollOffset.Y) sized (ActualWidth, Height). VisualLine.Height is the height of the entire line box, including all wrapped sub-rows for the document line, so this also correctly handles word-wrap (one DocumentLine that spans multiple visual rows gets one rectangle covering all of them, which is the same behavior the segment-rect loop had). No tests added for the rendering itself -- exercising AvalonEdit's VisualLine.VisualTop / Height accurately would require spinning up a real TextView with measured layout, which the test project deliberately avoids. The brush-selection logic (the only piece worth unit-testing here) is already covered by LineBackgroundBrushSelectorTests. AI-Local-Session: 4519f6b6-393a-4476-8efa-410e5396c3a9 AI-Cloud-Session: 72f9e474-60ab-42c2-b2a0-28fee827cbbb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 84a1704 commit 34f2348

3 files changed

Lines changed: 35 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ body. Keep section headings exact and write notes in Markdown.
3030

3131
### Fixed
3232

33+
- **Horizontal gaps between adjacent diff-tinted lines are gone.**
34+
Both background renderers used to paint each line's tint from
35+
`BackgroundGeometryBuilder.GetRectsFromVisualSegment`, which
36+
returns rectangles sized to the text-segment bounding box. On some
37+
DPI / line-spacing combinations that left a 1–2 px sliver of
38+
untinted background between adjacent rows. With the soft tints
39+
those slivers were invisible; with the new strong full-line tints
40+
they were obvious. The renderers now paint from `VisualLine.VisualTop`
41+
for the full `VisualLine.Height`, which is the actual line-box
42+
height (and handles word-wrap correctly).
3343
- **Paired delete+insert lines no longer render as yellow "Modified"
3444
when intra-line diff is off.** The side-by-side renderer used to
3545
treat any positionally-paired delete/insert as `Modified` (yellow

DiffViewer/Rendering/DiffBackgroundRenderer.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,19 @@ public void Draw(TextView textView, DrawingContext drawingContext)
6565

6666
Brush brush = LineBackgroundBrushSelector.Pick(_side, highlight.Kind, _scheme);
6767

68-
// Paint the full line width so the tint extends to the right edge
69-
// even on short lines; matches GitHub / VS Code line-diff style.
70-
foreach (var rect in BackgroundGeometryBuilder.GetRectsFromVisualSegment(
71-
textView, visualLine, 0, int.MaxValue))
72-
{
73-
var fullWidth = new Rect(
74-
rect.X,
75-
rect.Y,
76-
Math.Max(rect.Width, textView.ActualWidth - rect.X),
77-
rect.Height);
78-
drawingContext.DrawRectangle(brush, null, fullWidth);
79-
}
68+
// Paint the full visual-line box (VisualTop + Height) rather
69+
// than the text-segment rect from BackgroundGeometryBuilder:
70+
// the segment-rect approach leaves 1-2px horizontal gaps
71+
// between adjacent lines on some DPI / line-spacing settings.
72+
// VisualLine.Height covers all wrapped sub-rows for the
73+
// document line, so this works for word-wrap too. The full
74+
// ActualWidth ensures the tint extends to the right edge on
75+
// short lines (matches GitHub / VS Code line-diff style).
76+
double y = visualLine.VisualTop - textView.ScrollOffset.Y;
77+
drawingContext.DrawRectangle(
78+
brush,
79+
pen: null,
80+
new Rect(0, y, textView.ActualWidth, visualLine.Height));
8081
}
8182
}
8283
}

DiffViewer/Rendering/InlineDiffBackgroundRenderer.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ public void Draw(TextView textView, DrawingContext drawingContext)
4141

4242
Brush brush = LineBackgroundBrushSelector.Pick(DiffSide.Inline, highlight.Kind, _scheme);
4343

44-
foreach (var rect in BackgroundGeometryBuilder.GetRectsFromVisualSegment(
45-
textView, visualLine, 0, int.MaxValue))
46-
{
47-
var fullWidth = new Rect(
48-
rect.X,
49-
rect.Y,
50-
Math.Max(rect.Width, textView.ActualWidth - rect.X),
51-
rect.Height);
52-
drawingContext.DrawRectangle(brush, null, fullWidth);
53-
}
44+
// Paint the full visual-line box (VisualTop + Height) rather
45+
// than the text-segment rect from BackgroundGeometryBuilder:
46+
// the segment-rect approach leaves 1-2px horizontal gaps
47+
// between adjacent lines on some DPI / line-spacing settings.
48+
// VisualLine.Height covers all wrapped sub-rows for the
49+
// document line, so this works for word-wrap too. See the
50+
// matching comment in DiffBackgroundRenderer.Draw.
51+
double y = visualLine.VisualTop - textView.ScrollOffset.Y;
52+
drawingContext.DrawRectangle(
53+
brush,
54+
pen: null,
55+
new Rect(0, y, textView.ActualWidth, visualLine.Height));
5456
}
5557
}
5658
}

0 commit comments

Comments
 (0)