diff --git a/BizHawk.Common/UndoHistory.cs b/BizHawk.Common/UndoHistory.cs index 05be8e689b..eef6b72104 100644 --- a/BizHawk.Common/UndoHistory.cs +++ b/BizHawk.Common/UndoHistory.cs @@ -8,8 +8,11 @@ namespace BizHawk.Common private List> _history = new List>(); private int _curPos; // 1-based + public int MaxUndoLevels { get; set; } + public UndoHistory(bool enabled) { + MaxUndoLevels = 5; Enabled = enabled; } @@ -54,6 +57,15 @@ namespace BizHawk.Common } } + // TODO: don't assume we are one over, since MaxUndoLevels is public, it could be set to a small number after a large list has occured + if (_history.Count > MaxUndoLevels) + { + foreach (var item in _history.Take(_history.Count - MaxUndoLevels)) + { + _history.Remove(item); + } + } + _history.Add(newState.ToList()); _curPos = _history.Count; }