Browse Source
Fix Inlines clear handling (#14247 )
* Make sure to clean up VisualChildren and created text runs when the TextLayout is invalidate
* Remove localized comment
---------
Co-authored-by: Tim <47110241+timunie@users.noreply.github.com>
pull/14380/head
Benedikt Stebner
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
22 additions and
5 deletions
src/Avalonia.Controls/TextBlock.cs
tests/Avalonia.Controls.UnitTests/TextBlockTests.cs
@ -672,9 +672,12 @@ namespace Avalonia.Controls
{
{
_ textLayout ? . Dispose ( ) ;
_ textLayout ? . Dispose ( ) ;
_ textLayout = null ;
_ textLayout = null ;
VisualChildren . Clear ( ) ;
InvalidateVisual ( ) ;
_ textRuns = null ;
InvalidateVisual ( ) ;
InvalidateMeasure ( ) ;
InvalidateMeasure ( ) ;
}
}
@ -691,8 +694,6 @@ namespace Avalonia.Controls
if ( HasComplexContent )
if ( HasComplexContent )
{
{
VisualChildren . Clear ( ) ;
var textRuns = new List < TextRun > ( ) ;
var textRuns = new List < TextRun > ( ) ;
foreach ( var inline in inlines ! )
foreach ( var inline in inlines ! )
@ -876,9 +877,9 @@ namespace Avalonia.Controls
}
}
}
}
#pragma warning disable CA1815 // Equals und Gleichheitsoperator für Werttypen außer Kraft setzen
#pragma warning disable CA1815
protected readonly struct InlinesTextSource : ITextSource
protected readonly struct InlinesTextSource : ITextSource
#pragma warning restore CA1815 // Equals und Gleichheitsoperator für Werttypen außer Kraft setzen
#pragma warning restore CA1815
{
{
private readonly IReadOnlyList < TextRun > _ textRuns ;
private readonly IReadOnlyList < TextRun > _ textRuns ;
private readonly IReadOnlyList < ValueSpan < TextRunProperties > > ? _ textModifier ;
private readonly IReadOnlyList < ValueSpan < TextRunProperties > > ? _ textModifier ;
@ -224,5 +224,21 @@ namespace Avalonia.Controls.UnitTests
Assert . Equal ( underline , target . Inlines [ 0 ] . TextDecorations ) ;
Assert . Equal ( underline , target . Inlines [ 0 ] . TextDecorations ) ;
}
}
}
}
[Fact]
public void TextBlock_TextLines_Should_Be_Empty ( )
{
using ( UnitTestApplication . Start ( TestServices . MockPlatformRenderInterface ) )
{
var textblock = new TextBlock ( ) ;
textblock . Inlines ? . Add ( new Run ( "123" ) ) ;
textblock . Measure ( new Size ( 2 0 0 , 2 0 0 ) ) ;
int count = textblock . TextLayout . TextLines [ 0 ] . TextRuns . Count ;
textblock . Inlines ? . Clear ( ) ;
textblock . Measure ( new Size ( 2 0 0 , 2 0 0 ) ) ;
int count1 = textblock . TextLayout . TextLines [ 0 ] . TextRuns . Count ;
Assert . NotEqual ( count , count1 ) ;
}
}
}
}
}
}