Browse Source

Change property LastState on TryGetLastState method and add HasState property in UndoRedoHelper

pull/733/head
AndrewSt 10 years ago
parent
commit
795cb3bb9b
  1. 3
      src/Avalonia.Controls/TextBox.cs
  2. 13
      src/Avalonia.Controls/Utils/UndoRedoHelper.cs

3
src/Avalonia.Controls/TextBox.cs

@ -148,7 +148,8 @@ namespace Avalonia.Controls
{ {
value = CoerceCaretIndex(value); value = CoerceCaretIndex(value);
SetAndRaise(CaretIndexProperty, ref _caretIndex, value); SetAndRaise(CaretIndexProperty, ref _caretIndex, value);
if (_undoRedoHelper.IsLastState && _undoRedoHelper.LastState?.Text == Text) UndoRedoState state;
if (_undoRedoHelper.TryGetLastState(out state) && state.Text == Text)
_undoRedoHelper.UpdateLastState(); _undoRedoHelper.UpdateLastState();
} }
} }

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

@ -42,6 +42,17 @@ namespace Avalonia.Controls.Utils
public bool IsLastState => _currentNode != null && _currentNode.Next == null; public bool IsLastState => _currentNode != null && _currentNode.Next == null;
public bool TryGetLastState(out TState _state)
{
_state = default(TState);
if (!IsLastState)
return false;
_state = _currentNode.Value;
return true;
}
public bool HasState => _currentNode != null;
public void UpdateLastState(TState state) public void UpdateLastState(TState state)
{ {
_states.Last.Value = state; _states.Last.Value = state;
@ -52,8 +63,6 @@ namespace Avalonia.Controls.Utils
_states.Last.Value = _host.UndoRedoState; _states.Last.Value = _host.UndoRedoState;
} }
public TState? LastState => _currentNode?.Value;
public void DiscardRedo() public void DiscardRedo()
{ {
while (_currentNode?.Next != null) while (_currentNode?.Next != null)

Loading…
Cancel
Save