Skip to content

Commit

Permalink
Merge pull request #6039 from MarchingCube/fix-textpresenter-caretbrush
Browse files Browse the repository at this point in the history
Fix problems with mutable brush being passed to an immutable pen.
  • Loading branch information
grokys authored and danwalmsley committed Aug 17, 2021
1 parent a78345a commit 4fe4f3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/Avalonia.Controls/Presenters/TextPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ public override void Render(DrawingContext context)

RenderInternal(context);

if (selectionStart == selectionEnd)
if (selectionStart == selectionEnd && _caretBlink)
{
var caretBrush = CaretBrush;
var caretBrush = CaretBrush?.ToImmutable();

if (caretBrush is null)
{
Expand All @@ -382,13 +382,10 @@ public override void Render(DrawingContext context)
}
}

if (_caretBlink)
{
var (p1, p2) = GetCaretPoints();
context.DrawLine(
new ImmutablePen(caretBrush, 1),
p1, p2);
}
var (p1, p2) = GetCaretPoints();
context.DrawLine(
new ImmutablePen(caretBrush, 1),
p1, p2);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Avalonia.Visuals/Media/Immutable/ImmutablePen.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Avalonia.Media.Immutable
{
Expand Down Expand Up @@ -44,6 +45,8 @@ public ImmutablePen(
PenLineJoin lineJoin = PenLineJoin.Miter,
double miterLimit = 10.0)
{
Debug.Assert(!(brush is IMutableBrush));

Brush = brush;
Thickness = thickness;
LineCap = lineCap;
Expand Down

0 comments on commit 4fe4f3e

Please sign in to comment.