/// <summary>
        /// Undo the number of actions specified by <paramref name="count"/>.
        /// </summary>
        /// <param name="count">The number of actions to undo.</param>
        public void Undo(int count = 1)
        {
            lock (LockObject)
            {
                if (count > UndoActions.Count)
                {
                    throw new ArgumentOutOfRangeException("Can't undo the number of actions specified.", nameof(count));
                }

                IsUndoing = true;
                for (var i = 0; i < count; i++)
                {
                    // Get the next action to undo.
                    var action = UndoActions.Peek();
                    OnBeforeUndo(new UndoEventArgs(action));
                    action.Undo();

                    // Add the action to the redo stack.
                    RedoActions.Push(UndoActions.Pop());
                    OnAfterUndo(new UndoEventArgs(action));
                }
                IsUndoing = false;
                OnChanged(EventArgs.Empty);
            }
        }
Beispiel #2
0
        public bool Undo(out TextCursor cursor)
        {
            cursor = null;
            if (!UndoActions.Any())
            {
                return(false);
            }
            var action = UndoActions.Pop();

            cursor = action.Cursor;
            cursor.Undo(action);
            RedoActions.Push(action);
            return(UndoActions.Any());
        }