diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index b4a8095247..34c6b1cfd6 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -85,6 +85,7 @@ namespace Avalonia.Controls private int _selectionEnd; private TextPresenter _presenter; private UndoRedoHelper _undoRedoHelper; + private bool _isUndoingRedoing; private bool _ignoreTextChanges; private static readonly string[] invalidCharacters = new String[1]{"\u007f"}; @@ -198,7 +199,11 @@ namespace Avalonia.Controls if (!_ignoreTextChanges) { CaretIndex = CoerceCaretIndex(CaretIndex, value?.Length ?? 0); - SetAndRaise(TextProperty, ref _text, value); + + if (SetAndRaise(TextProperty, ref _text, value) && !_isUndoingRedoing) + { + _undoRedoHelper.Clear(); + } } } } @@ -367,14 +372,30 @@ namespace Avalonia.Controls case Key.Z: if (modifiers == InputModifiers.Control) { - _undoRedoHelper.Undo(); + try + { + _isUndoingRedoing = true; + _undoRedoHelper.Undo(); + } + finally + { + _isUndoingRedoing = false; + } handled = true; } break; case Key.Y: if (modifiers == InputModifiers.Control) { - _undoRedoHelper.Redo(); + try + { + _isUndoingRedoing = true; + _undoRedoHelper.Redo(); + } + finally + { + _isUndoingRedoing = false; + } handled = true; } break; diff --git a/src/Avalonia.Controls/Utils/UndoRedoHelper.cs b/src/Avalonia.Controls/Utils/UndoRedoHelper.cs index be4c1aa6c4..c76555e554 100644 --- a/src/Avalonia.Controls/Utils/UndoRedoHelper.cs +++ b/src/Avalonia.Controls/Utils/UndoRedoHelper.cs @@ -91,6 +91,11 @@ namespace Avalonia.Controls.Utils } } + public void Clear() + { + _states.Clear(); + } + bool WeakTimer.IWeakTimerSubscriber.Tick() { Snapshot();