|
|
@ -30,10 +30,13 @@ namespace Avalonia.Controls |
|
|
nameof(CaretIndex), |
|
|
nameof(CaretIndex), |
|
|
o => o.CaretIndex, |
|
|
o => o.CaretIndex, |
|
|
(o, v) => o.CaretIndex = v); |
|
|
(o, v) => o.CaretIndex = v); |
|
|
|
|
|
|
|
|
public static readonly StyledProperty<bool> IsReadOnlyProperty = |
|
|
public static readonly StyledProperty<bool> IsReadOnlyProperty = |
|
|
AvaloniaProperty.Register<TextBox, bool>(nameof(IsReadOnly)); |
|
|
AvaloniaProperty.Register<TextBox, bool>(nameof(IsReadOnly)); |
|
|
|
|
|
|
|
|
|
|
|
public static readonly StyledProperty<char> PasswordCharProperty = |
|
|
|
|
|
AvaloniaProperty.Register<TextBox, char>(nameof(PasswordChar)); |
|
|
|
|
|
|
|
|
public static readonly DirectProperty<TextBox, int> SelectionStartProperty = |
|
|
public static readonly DirectProperty<TextBox, int> SelectionStartProperty = |
|
|
AvaloniaProperty.RegisterDirect<TextBox, int>( |
|
|
AvaloniaProperty.RegisterDirect<TextBox, int>( |
|
|
nameof(SelectionStart), |
|
|
nameof(SelectionStart), |
|
|
@ -87,7 +90,7 @@ namespace Avalonia.Controls |
|
|
private UndoRedoHelper<UndoRedoState> _undoRedoHelper; |
|
|
private UndoRedoHelper<UndoRedoState> _undoRedoHelper; |
|
|
private bool _isUndoingRedoing; |
|
|
private bool _isUndoingRedoing; |
|
|
private bool _ignoreTextChanges; |
|
|
private bool _ignoreTextChanges; |
|
|
private static readonly string[] invalidCharacters = new String[1]{"\u007f"}; |
|
|
private static readonly string[] invalidCharacters = new String[1] { "\u007f" }; |
|
|
|
|
|
|
|
|
static TextBox() |
|
|
static TextBox() |
|
|
{ |
|
|
{ |
|
|
@ -116,7 +119,7 @@ namespace Avalonia.Controls |
|
|
ScrollViewer.HorizontalScrollBarVisibilityProperty, |
|
|
ScrollViewer.HorizontalScrollBarVisibilityProperty, |
|
|
horizontalScrollBarVisibility, |
|
|
horizontalScrollBarVisibility, |
|
|
BindingPriority.Style); |
|
|
BindingPriority.Style); |
|
|
_undoRedoHelper = new UndoRedoHelper<UndoRedoState>(this); |
|
|
_undoRedoHelper = new UndoRedoHelper<UndoRedoState>(this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public bool AcceptsReturn |
|
|
public bool AcceptsReturn |
|
|
@ -147,13 +150,19 @@ namespace Avalonia.Controls |
|
|
_undoRedoHelper.UpdateLastState(); |
|
|
_undoRedoHelper.UpdateLastState(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public bool IsReadOnly |
|
|
public bool IsReadOnly |
|
|
{ |
|
|
{ |
|
|
get { return GetValue(IsReadOnlyProperty); } |
|
|
get { return GetValue(IsReadOnlyProperty); } |
|
|
set { SetValue(IsReadOnlyProperty, value); } |
|
|
set { SetValue(IsReadOnlyProperty, value); } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public char PasswordChar |
|
|
|
|
|
{ |
|
|
|
|
|
get => GetValue(PasswordCharProperty); |
|
|
|
|
|
set => SetValue(PasswordCharProperty, value); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public int SelectionStart |
|
|
public int SelectionStart |
|
|
{ |
|
|
{ |
|
|
get |
|
|
get |
|
|
@ -237,7 +246,7 @@ namespace Avalonia.Controls |
|
|
_presenter = e.NameScope.Get<TextPresenter>("PART_TextPresenter"); |
|
|
_presenter = e.NameScope.Get<TextPresenter>("PART_TextPresenter"); |
|
|
_presenter.Cursor = new Cursor(StandardCursorType.Ibeam); |
|
|
_presenter.Cursor = new Cursor(StandardCursorType.Ibeam); |
|
|
|
|
|
|
|
|
if(IsFocused) |
|
|
if (IsFocused) |
|
|
{ |
|
|
{ |
|
|
_presenter.ShowCaret(); |
|
|
_presenter.ShowCaret(); |
|
|
} |
|
|
} |
|
|
@ -349,7 +358,10 @@ namespace Avalonia.Controls |
|
|
case Key.C: |
|
|
case Key.C: |
|
|
if (modifiers == InputModifiers.Control) |
|
|
if (modifiers == InputModifiers.Control) |
|
|
{ |
|
|
{ |
|
|
Copy(); |
|
|
if (!IsPasswordBox) |
|
|
|
|
|
{ |
|
|
|
|
|
Copy(); |
|
|
|
|
|
} |
|
|
handled = true; |
|
|
handled = true; |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
@ -357,8 +369,11 @@ namespace Avalonia.Controls |
|
|
case Key.X: |
|
|
case Key.X: |
|
|
if (modifiers == InputModifiers.Control) |
|
|
if (modifiers == InputModifiers.Control) |
|
|
{ |
|
|
{ |
|
|
Copy(); |
|
|
if (!IsPasswordBox) |
|
|
DeleteSelection(); |
|
|
{ |
|
|
|
|
|
Copy(); |
|
|
|
|
|
DeleteSelection(); |
|
|
|
|
|
} |
|
|
handled = true; |
|
|
handled = true; |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
@ -578,7 +593,7 @@ namespace Avalonia.Controls |
|
|
DataValidationErrors.SetError(this, status.Error); |
|
|
DataValidationErrors.SetError(this, status.Error); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private int CoerceCaretIndex(int value) => CoerceCaretIndex(value, Text?.Length ?? 0); |
|
|
private int CoerceCaretIndex(int value) => CoerceCaretIndex(value, Text?.Length ?? 0); |
|
|
|
|
|
|
|
|
private int CoerceCaretIndex(int value, int length) |
|
|
private int CoerceCaretIndex(int value, int length) |
|
|
@ -856,6 +871,8 @@ namespace Avalonia.Controls |
|
|
SelectionEnd = CaretIndex; |
|
|
SelectionEnd = CaretIndex; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private bool IsPasswordBox => PasswordChar != default(char); |
|
|
|
|
|
|
|
|
UndoRedoState UndoRedoHelper<UndoRedoState>.IUndoRedoHost.UndoRedoState |
|
|
UndoRedoState UndoRedoHelper<UndoRedoState>.IUndoRedoHost.UndoRedoState |
|
|
{ |
|
|
{ |
|
|
get { return new UndoRedoState(Text, CaretIndex); } |
|
|
get { return new UndoRedoState(Text, CaretIndex); } |
|
|
|