Browse Source

Fix logical parent cleanup

pull/9245/head
Benedikt Stebner 3 years ago
parent
commit
e639aead67
  1. 20
      src/Avalonia.Controls/Documents/InlineCollection.cs
  2. 6
      src/Avalonia.Controls/Documents/Span.cs
  3. 6
      src/Avalonia.Controls/TextBlock.cs

20
src/Avalonia.Controls/Documents/InlineCollection.cs

@ -12,7 +12,7 @@ namespace Avalonia.Controls.Documents
[WhitespaceSignificantCollection]
public class InlineCollection : AvaloniaList<Inline>
{
private IAvaloniaList<ILogical>? _parent;
private IAvaloniaList<ILogical>? _logicalChildren;
private IInlineHost? _inlineHost;
/// <summary>
@ -26,26 +26,28 @@ namespace Avalonia.Controls.Documents
x =>
{
x.InlineHost = InlineHost;
Parent?.Add(x);
LogicalChildren?.Add(x);
Invalidate();
},
x =>
{
Parent?.Remove(x);
LogicalChildren?.Remove(x);
x.InlineHost = InlineHost;
Invalidate();
},
() => throw new NotSupportedException());
}
internal IAvaloniaList<ILogical>? Parent
internal IAvaloniaList<ILogical>? LogicalChildren
{
get => _parent;
get => _logicalChildren;
set
{
_parent = value;
var oldValue = _logicalChildren;
OnParentChanged(_parent, value);
_logicalChildren = value;
OnParentChanged(oldValue, value);
}
}
@ -116,7 +118,7 @@ namespace Avalonia.Controls.Documents
private void AddText(string text)
{
if (Parent is TextBlock textBlock && !textBlock.HasComplexContent)
if (LogicalChildren is TextBlock textBlock && !textBlock.HasComplexContent)
{
textBlock._text += text;
}
@ -128,7 +130,7 @@ namespace Avalonia.Controls.Documents
private void OnAdd()
{
if (Parent is TextBlock textBlock)
if (LogicalChildren is TextBlock textBlock)
{
if (!textBlock.HasComplexContent && !string.IsNullOrEmpty(textBlock._text))
{

6
src/Avalonia.Controls/Documents/Span.cs

@ -21,7 +21,7 @@ namespace Avalonia.Controls.Documents
{
Inlines = new InlineCollection
{
Parent = LogicalChildren
LogicalChildren = LogicalChildren
};
}
@ -78,14 +78,14 @@ namespace Avalonia.Controls.Documents
{
if (oldValue is not null)
{
oldValue.Parent = null;
oldValue.LogicalChildren = null;
oldValue.InlineHost = null;
oldValue.Invalidated -= (s, e) => InlineHost?.Invalidate();
}
if (newValue is not null)
{
newValue.Parent = LogicalChildren;
newValue.LogicalChildren = LogicalChildren;
newValue.InlineHost = InlineHost;
newValue.Invalidated += (s, e) => InlineHost?.Invalidate();
}

6
src/Avalonia.Controls/TextBlock.cs

@ -156,7 +156,7 @@ namespace Avalonia.Controls
{
Inlines = new InlineCollection
{
Parent = LogicalChildren,
LogicalChildren = LogicalChildren,
InlineHost = this
};
}
@ -772,14 +772,14 @@ namespace Avalonia.Controls
{
if (oldValue is not null)
{
oldValue.Parent = null;
oldValue.LogicalChildren = null;
oldValue.InlineHost = null;
oldValue.Invalidated -= (s, e) => InvalidateTextLayout();
}
if (newValue is not null)
{
newValue.Parent = LogicalChildren;
newValue.LogicalChildren = LogicalChildren;
newValue.InlineHost = this;
newValue.Invalidated += (s, e) => InvalidateTextLayout();
}

Loading…
Cancel
Save