|
|
@ -53,7 +53,7 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
|
public static readonly StyledProperty<char> PasswordCharProperty = |
|
|
public static readonly StyledProperty<char> PasswordCharProperty = |
|
|
AvaloniaProperty.Register<TextBox, char>(nameof(PasswordChar)); |
|
|
AvaloniaProperty.Register<TextBox, char>(nameof(PasswordChar)); |
|
|
|
|
|
|
|
|
public static readonly StyledProperty<IBrush?> SelectionBrushProperty = |
|
|
public static readonly StyledProperty<IBrush?> SelectionBrushProperty = |
|
|
AvaloniaProperty.Register<TextBox, IBrush?>(nameof(SelectionBrush)); |
|
|
AvaloniaProperty.Register<TextBox, IBrush?>(nameof(SelectionBrush)); |
|
|
|
|
|
|
|
|
@ -196,7 +196,6 @@ namespace Avalonia.Controls |
|
|
private TextBoxTextInputMethodClient _imClient = new TextBoxTextInputMethodClient(); |
|
|
private TextBoxTextInputMethodClient _imClient = new TextBoxTextInputMethodClient(); |
|
|
private UndoRedoHelper<UndoRedoState> _undoRedoHelper; |
|
|
private UndoRedoHelper<UndoRedoState> _undoRedoHelper; |
|
|
private bool _isUndoingRedoing; |
|
|
private bool _isUndoingRedoing; |
|
|
private bool _ignoreTextChanges; |
|
|
|
|
|
private bool _canCut; |
|
|
private bool _canCut; |
|
|
private bool _canCopy; |
|
|
private bool _canCopy; |
|
|
private bool _canPaste; |
|
|
private bool _canPaste; |
|
|
@ -276,7 +275,7 @@ namespace Avalonia.Controls |
|
|
get => GetValue(IsReadOnlyProperty); |
|
|
get => GetValue(IsReadOnlyProperty); |
|
|
set => SetValue(IsReadOnlyProperty, value); |
|
|
set => SetValue(IsReadOnlyProperty, value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public char PasswordChar |
|
|
public char PasswordChar |
|
|
{ |
|
|
{ |
|
|
get => GetValue(PasswordCharProperty); |
|
|
get => GetValue(PasswordCharProperty); |
|
|
@ -368,21 +367,17 @@ namespace Avalonia.Controls |
|
|
get => _text; |
|
|
get => _text; |
|
|
set |
|
|
set |
|
|
{ |
|
|
{ |
|
|
if (!_ignoreTextChanges) |
|
|
var caretIndex = CaretIndex; |
|
|
{ |
|
|
var selectionStart = SelectionStart; |
|
|
var caretIndex = CaretIndex; |
|
|
var selectionEnd = SelectionEnd; |
|
|
var selectionStart = SelectionStart; |
|
|
|
|
|
var selectionEnd = SelectionEnd; |
|
|
|
|
|
|
|
|
|
|
|
CaretIndex = CoerceCaretIndex(caretIndex, value); |
|
|
CaretIndex = CoerceCaretIndex(caretIndex, value); |
|
|
SelectionStart = CoerceCaretIndex(selectionStart, value); |
|
|
SelectionStart = CoerceCaretIndex(selectionStart, value); |
|
|
SelectionEnd = CoerceCaretIndex(selectionEnd, value); |
|
|
SelectionEnd = CoerceCaretIndex(selectionEnd, value); |
|
|
|
|
|
if (SetAndRaise(TextProperty, ref _text, value) && IsUndoEnabled && !_isUndoingRedoing) |
|
|
if (SetAndRaise(TextProperty, ref _text, value) && IsUndoEnabled && !_isUndoingRedoing) |
|
|
{ |
|
|
{ |
|
|
_undoRedoHelper.Clear(); |
|
|
_undoRedoHelper.Clear(); |
|
|
SnapshotUndoRedo(); // so we always have an initial state
|
|
|
SnapshotUndoRedo(); // so we always have an initial state
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -736,32 +731,23 @@ namespace Avalonia.Controls |
|
|
{ |
|
|
{ |
|
|
var oldText = _text; |
|
|
var oldText = _text; |
|
|
|
|
|
|
|
|
_ignoreTextChanges = true; |
|
|
DeleteSelection(false); |
|
|
|
|
|
var caretIndex = CaretIndex; |
|
|
try |
|
|
text = Text ?? string.Empty; |
|
|
{ |
|
|
SetTextInternal(text.Substring(0, caretIndex) + input + text.Substring(caretIndex)); |
|
|
DeleteSelection(false); |
|
|
ClearSelection(); |
|
|
var caretIndex = CaretIndex; |
|
|
|
|
|
text = Text ?? string.Empty; |
|
|
|
|
|
SetTextInternal(text.Substring(0, caretIndex) + input + text.Substring(caretIndex)); |
|
|
|
|
|
ClearSelection(); |
|
|
|
|
|
|
|
|
|
|
|
if (IsUndoEnabled) |
|
|
|
|
|
{ |
|
|
|
|
|
_undoRedoHelper.DiscardRedo(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (_text != oldText) |
|
|
|
|
|
{ |
|
|
|
|
|
RaisePropertyChanged(TextProperty, oldText, _text); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CaretIndex = caretIndex + input.Length; |
|
|
if (IsUndoEnabled) |
|
|
|
|
|
{ |
|
|
|
|
|
_undoRedoHelper.DiscardRedo(); |
|
|
} |
|
|
} |
|
|
finally |
|
|
|
|
|
|
|
|
if (_text != oldText) |
|
|
{ |
|
|
{ |
|
|
_ignoreTextChanges = false; |
|
|
RaisePropertyChanged(TextProperty, oldText, _text); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CaretIndex = caretIndex + input.Length; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1499,15 +1485,7 @@ namespace Avalonia.Controls |
|
|
{ |
|
|
{ |
|
|
if (raiseTextChanged) |
|
|
if (raiseTextChanged) |
|
|
{ |
|
|
{ |
|
|
try |
|
|
SetAndRaise(TextProperty, ref _text, value); |
|
|
{ |
|
|
|
|
|
_ignoreTextChanges = true; |
|
|
|
|
|
SetAndRaise(TextProperty, ref _text, value); |
|
|
|
|
|
} |
|
|
|
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
_ignoreTextChanges = false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
|