示例#1
0
        /// <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);
            }
        }
示例#2
0
 public TextAction PeekIf(TextCursor cursor, TextAction.ActionType type, Func <TextAction, bool> condition)
 {
     if (UndoActions.Any() && UndoActions.Peek().Match(cursor, type) && condition(UndoActions.Peek()))
     {
         return(UndoActions.Peek());
     }
     else
     {
         return(Add(cursor, type));
     }
 }
示例#3
0
 public TextAction PeekOrAdd(TextCursor cursor, TextAction.ActionType type)
 {
     if (UndoActions.Any() && UndoActions.Peek().Match(cursor, type))
     {
         return(UndoActions.Peek());
     }
     else
     {
         return(Add(cursor, type));
     }
 }