Browse Source
Fixes/inline host change propagation (#14914)
* Add failing test
* Propagate InlineHost to children
pull/14921/head
Benedikt Stebner
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
24 additions and
3 deletions
-
src/Avalonia.Controls/Documents/InlineCollection.cs
-
src/Avalonia.Controls/Documents/Span.cs
-
tests/Avalonia.Controls.UnitTests/TextBlockTests.cs
|
|
|
@ -159,6 +159,8 @@ namespace Avalonia.Controls.Documents |
|
|
|
{ |
|
|
|
foreach (var child in this) |
|
|
|
{ |
|
|
|
child.InlineHost = newValue; |
|
|
|
|
|
|
|
if (child is not InlineUIContainer container) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
|
|
|
|
@ -77,9 +77,6 @@ namespace Avalonia.Controls.Documents |
|
|
|
|
|
|
|
private void OnInlinesChanged(InlineCollection? oldValue, InlineCollection? newValue) |
|
|
|
{ |
|
|
|
void OnInlinesInvalidated(object? sender, EventArgs e) |
|
|
|
=> InlineHost?.Invalidate(); |
|
|
|
|
|
|
|
if (oldValue is not null) |
|
|
|
{ |
|
|
|
oldValue.LogicalChildren = null; |
|
|
|
@ -93,6 +90,11 @@ namespace Avalonia.Controls.Documents |
|
|
|
newValue.InlineHost = InlineHost; |
|
|
|
newValue.Invalidated += OnInlinesInvalidated; |
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
void OnInlinesInvalidated(object? sender, EventArgs e) |
|
|
|
=> InlineHost?.Invalidate(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -205,6 +205,23 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Changing_InlineHost_Should_Propagate_To_Nested_Inlines() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) |
|
|
|
{ |
|
|
|
var target = new TextBlock(); |
|
|
|
|
|
|
|
var span = new Span { Inlines = new InlineCollection { new Run { Text = "World" } } }; |
|
|
|
|
|
|
|
var inlines = new InlineCollection{ new Run{Text = "Hello "}, span }; |
|
|
|
|
|
|
|
target.Inlines = inlines; |
|
|
|
|
|
|
|
Assert.Equal(target, span.InlineHost); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Changing_Inlines_Should_Reset_VisualChildren() |
|
|
|
{ |
|
|
|
|