Browse Source

Merge pull request #1450 from AvaloniaUI/fixes/336-undo-redo-bindings

Clear TextBox undo stack on binding change.
pull/1480/head
Steven Kirk 9 years ago
committed by GitHub
parent
commit
829d6957e2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      src/Avalonia.Controls/TextBox.cs
  2. 5
      src/Avalonia.Controls/Utils/UndoRedoHelper.cs

27
src/Avalonia.Controls/TextBox.cs

@ -85,6 +85,7 @@ namespace Avalonia.Controls
private int _selectionEnd; private int _selectionEnd;
private TextPresenter _presenter; private TextPresenter _presenter;
private UndoRedoHelper<UndoRedoState> _undoRedoHelper; private UndoRedoHelper<UndoRedoState> _undoRedoHelper;
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"};
@ -198,7 +199,11 @@ namespace Avalonia.Controls
if (!_ignoreTextChanges) if (!_ignoreTextChanges)
{ {
CaretIndex = CoerceCaretIndex(CaretIndex, value?.Length ?? 0); 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: case Key.Z:
if (modifiers == InputModifiers.Control) if (modifiers == InputModifiers.Control)
{ {
_undoRedoHelper.Undo(); try
{
_isUndoingRedoing = true;
_undoRedoHelper.Undo();
}
finally
{
_isUndoingRedoing = false;
}
handled = true; handled = true;
} }
break; break;
case Key.Y: case Key.Y:
if (modifiers == InputModifiers.Control) if (modifiers == InputModifiers.Control)
{ {
_undoRedoHelper.Redo(); try
{
_isUndoingRedoing = true;
_undoRedoHelper.Redo();
}
finally
{
_isUndoingRedoing = false;
}
handled = true; handled = true;
} }
break; break;

5
src/Avalonia.Controls/Utils/UndoRedoHelper.cs

@ -91,6 +91,11 @@ namespace Avalonia.Controls.Utils
} }
} }
public void Clear()
{
_states.Clear();
}
bool WeakTimer.IWeakTimerSubscriber.Tick() bool WeakTimer.IWeakTimerSubscriber.Tick()
{ {
Snapshot(); Snapshot();

Loading…
Cancel
Save