Browse Source

Fix problems with mutable brush being passed to an immutable pen.

Dariusz Komosinski 4 năm trước cách đây
mục cha
commit
6f5bf52178

+ 6 - 9
src/Avalonia.Controls/Presenters/TextPresenter.cs

@@ -361,9 +361,9 @@ namespace Avalonia.Controls.Presenters
 
 
             RenderInternal(context);
             RenderInternal(context);
 
 
-            if (selectionStart == selectionEnd)
+            if (selectionStart == selectionEnd && _caretBlink)
             {
             {
-                var caretBrush = CaretBrush;
+                var caretBrush = CaretBrush?.ToImmutable();
 
 
                 if (caretBrush is null)
                 if (caretBrush is null)
                 {
                 {
@@ -382,13 +382,10 @@ namespace Avalonia.Controls.Presenters
                     }
                     }
                 }
                 }
 
 
-                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);
             }
             }
         }
         }
 
 

+ 3 - 0
src/Avalonia.Visuals/Media/Immutable/ImmutablePen.cs

@@ -1,5 +1,6 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
+using System.Diagnostics;
 
 
 namespace Avalonia.Media.Immutable
 namespace Avalonia.Media.Immutable
 {
 {
@@ -44,6 +45,8 @@ namespace Avalonia.Media.Immutable
             PenLineJoin lineJoin = PenLineJoin.Miter,
             PenLineJoin lineJoin = PenLineJoin.Miter,
             double miterLimit = 10.0)
             double miterLimit = 10.0)
         {
         {
+            Debug.Assert(!(brush is IMutableBrush));
+
             Brush = brush;
             Brush = brush;
             Thickness = thickness;
             Thickness = thickness;
             LineCap = lineCap;
             LineCap = lineCap;