|
|
@ -19,10 +19,10 @@ namespace Avalonia.Controls |
|
|
public class SelectableTextBlock : TextBlock, IInlineHost |
|
|
public class SelectableTextBlock : TextBlock, IInlineHost |
|
|
{ |
|
|
{ |
|
|
public static readonly StyledProperty<int> SelectionStartProperty = |
|
|
public static readonly StyledProperty<int> SelectionStartProperty = |
|
|
TextBox.SelectionStartProperty.AddOwner<SelectableTextBlock>(new(coerce: TextBox.CoerceCaretIndex)); |
|
|
TextBox.SelectionStartProperty.AddOwner<SelectableTextBlock>(); |
|
|
|
|
|
|
|
|
public static readonly StyledProperty<int> SelectionEndProperty = |
|
|
public static readonly StyledProperty<int> SelectionEndProperty = |
|
|
TextBox.SelectionEndProperty.AddOwner<SelectableTextBlock>(new(coerce: TextBox.CoerceCaretIndex)); |
|
|
TextBox.SelectionEndProperty.AddOwner<SelectableTextBlock>(); |
|
|
|
|
|
|
|
|
public static readonly DirectProperty<SelectableTextBlock, string> SelectedTextProperty = |
|
|
public static readonly DirectProperty<SelectableTextBlock, string> SelectedTextProperty = |
|
|
AvaloniaProperty.RegisterDirect<SelectableTextBlock, string>( |
|
|
AvaloniaProperty.RegisterDirect<SelectableTextBlock, string>( |
|
|
@ -231,7 +231,7 @@ namespace Avalonia.Controls |
|
|
{ |
|
|
{ |
|
|
base.OnPointerPressed(e); |
|
|
base.OnPointerPressed(e); |
|
|
|
|
|
|
|
|
var text = Text; |
|
|
var text = HasComplexContent ? Inlines?.Text : Text; |
|
|
var clickInfo = e.GetCurrentPoint(this); |
|
|
var clickInfo = e.GetCurrentPoint(this); |
|
|
|
|
|
|
|
|
if (text != null && clickInfo.Properties.IsLeftButtonPressed) |
|
|
if (text != null && clickInfo.Properties.IsLeftButtonPressed) |
|
|
@ -317,7 +317,7 @@ namespace Avalonia.Controls |
|
|
// selection should not change during pointer move if the user right clicks
|
|
|
// selection should not change during pointer move if the user right clicks
|
|
|
if (e.Pointer.Captured == this && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) |
|
|
if (e.Pointer.Captured == this && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) |
|
|
{ |
|
|
{ |
|
|
var text = Text; |
|
|
var text = HasComplexContent ? Inlines?.Text : Text; |
|
|
var padding = Padding; |
|
|
var padding = Padding; |
|
|
|
|
|
|
|
|
var point = e.GetPosition(this) - new Point(padding.Left, padding.Top); |
|
|
var point = e.GetPosition(this) - new Point(padding.Left, padding.Top); |
|
|
@ -400,7 +400,10 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
|
private string GetSelection() |
|
|
private string GetSelection() |
|
|
{ |
|
|
{ |
|
|
var textLength = Text?.Length ?? 0; |
|
|
var text = HasComplexContent ? Inlines?.Text : Text; |
|
|
|
|
|
|
|
|
|
|
|
var textLength = text?.Length ?? 0; |
|
|
|
|
|
|
|
|
if (textLength == 0) |
|
|
if (textLength == 0) |
|
|
{ |
|
|
{ |
|
|
return ""; |
|
|
return ""; |
|
|
@ -418,7 +421,7 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
|
var length = Math.Max(0, end - start); |
|
|
var length = Math.Max(0, end - start); |
|
|
|
|
|
|
|
|
var selectedText = Text!.Substring(start, length); |
|
|
var selectedText = text!.Substring(start, length); |
|
|
|
|
|
|
|
|
return selectedText; |
|
|
return selectedText; |
|
|
} |
|
|
} |
|
|
|