diff --git a/src/Avalonia.Controls/SelectableTextBlock.cs b/src/Avalonia.Controls/SelectableTextBlock.cs index 1007001f05..8622720236 100644 --- a/src/Avalonia.Controls/SelectableTextBlock.cs +++ b/src/Avalonia.Controls/SelectableTextBlock.cs @@ -18,10 +18,10 @@ namespace Avalonia.Controls public class SelectableTextBlock : TextBlock, IInlineHost { public static readonly StyledProperty SelectionStartProperty = - TextBox.SelectionStartProperty.AddOwner(new(coerce: TextBox.CoerceCaretIndex)); + TextBox.SelectionStartProperty.AddOwner(); public static readonly StyledProperty SelectionEndProperty = - TextBox.SelectionEndProperty.AddOwner(new(coerce: TextBox.CoerceCaretIndex)); + TextBox.SelectionEndProperty.AddOwner(); public static readonly DirectProperty SelectedTextProperty = AvaloniaProperty.RegisterDirect( @@ -228,7 +228,7 @@ namespace Avalonia.Controls { base.OnPointerPressed(e); - var text = Text; + var text = HasComplexContent ? Inlines.Text : Text; var clickInfo = e.GetCurrentPoint(this); if (text != null && clickInfo.Properties.IsLeftButtonPressed) @@ -314,7 +314,7 @@ namespace Avalonia.Controls // selection should not change during pointer move if the user right clicks if (e.Pointer.Captured == this && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) { - var text = Text; + var text = HasComplexContent ? Inlines.Text : Text; var padding = Padding; var point = e.GetPosition(this) - new Point(padding.Left, padding.Top); @@ -397,7 +397,10 @@ namespace Avalonia.Controls private string GetSelection() { - var textLength = Text?.Length ?? 0; + var text = HasComplexContent ? Inlines.Text : Text; + + var textLength = text?.Length ?? 0; + if (textLength == 0) { return ""; @@ -415,7 +418,7 @@ namespace Avalonia.Controls var length = Math.Max(0, end - start); - var selectedText = Text!.Substring(start, length); + var selectedText = text!.Substring(start, length); return selectedText; }