public bool CanMerge(ITextUndoTransaction newTransaction, ITextUndoTransaction oldTransaction) { MergeUndoActionPolicy oldPolicy = oldTransaction.MergePolicy as MergeUndoActionPolicy; MergeUndoActionPolicy newPolicy = newTransaction.MergePolicy as MergeUndoActionPolicy; if (oldPolicy != null && oldPolicy._mergeNext && newPolicy != null && newPolicy._mergePrevious && oldPolicy._actionName == newPolicy._actionName) { // If one of the transactions is empty, than it is safe to merge if (newTransaction.UndoPrimitives.Count == 0 || oldTransaction.UndoPrimitives.Count == 0) { return(true); } // Make sure that we only merge consecutive edits ITextUndoPrimitive newPrimitive = newTransaction.UndoPrimitives[0]; ITextUndoPrimitive oldPrimitive = oldTransaction.UndoPrimitives[oldTransaction.UndoPrimitives.Count - 1]; return(newPrimitive.CanMerge(oldPrimitive)); } return(false); }
/// <summary> /// AddUndo adds a new primitive to the end of the list when the transaction is Open. /// </summary> /// <param name="undo"></param> public void AddUndo(ITextUndoPrimitive undo) { _primitives.Add(undo); undo.Parent = this; MergeMostRecentUndoPrimitive(); }
/// <summary> /// This is called by AddUndo, so that primitives are always in a fully merged state as we go. /// </summary> protected void MergeMostRecentUndoPrimitive() { // no merging unless there are at least two items if (_primitives.Count < 2) { return; } var top = _primitives[_primitives.Count - 1]; ITextUndoPrimitive victim = null; var victimIndex = -1; for (var i = _primitives.Count - 2; i >= 0; --i) { if (top.GetType() == _primitives[i].GetType() && top.CanMerge(_primitives[i])) { victim = _primitives[i]; victimIndex = i; break; } } if (victim != null) { var newPrimitive = top.Merge(victim); _primitives.RemoveRange(_primitives.Count - 1, 1); _primitives.RemoveRange(victimIndex, 1); _primitives.Add(newPrimitive); } }
public ITextUndoPrimitive Merge(ITextUndoPrimitive older) { if (older == null) { throw new ArgumentNullException(nameof(older)); } throw new NotSupportedException(); //TODO: }
public void AddUndo(ITextUndoPrimitive undo) { if (undo == null) throw new ArgumentNullException(nameof(undo)); if (State != UndoTransactionState.Open) throw new InvalidOperationException(); undoPrimitives.Add(undo); undo.Parent = this; }
public bool CanMerge(ITextUndoPrimitive older) { if (older == null) { throw new ArgumentNullException(nameof(older)); } return(false); //TODO: }
/// <summary> /// AddUndo adds a new primitive to the end of the list when the transaction is Open. /// </summary> /// <param name="undo"></param> public void AddUndo(ITextUndoPrimitive undo) { Check.InvalidOperation(() => State == UndoTransactionState.Open, "Cancel called on transation that is not opened"); _primitives.Add(undo); undo.Parent = this; MergeMostRecentUndoPrimitive(); }
/// <summary> /// AddUndo adds a new primitive to the end of the list when the transaction is Open. /// </summary> /// <param name="undo"></param> public void AddUndo(ITextUndoPrimitive undo) { if (State != UndoTransactionState.Open) { throw new InvalidOperationException("Strings.AddUndoCalledOnTransationThatIsNotOpened"); } _primitives.Add(undo); undo.Parent = this; MergeMostRecentUndoPrimitive(); }
public void AddUndo(ITextUndoPrimitive undo) { if (undo == null) { throw new ArgumentNullException(nameof(undo)); } if (State != UndoTransactionState.Open) { throw new InvalidOperationException(); } undoPrimitives.Add(undo); undo.Parent = this; }
public bool CanMerge(ITextUndoTransaction newTransaction, ITextUndoTransaction oldTransaction) { // Validate if (newTransaction == null) { throw new ArgumentNullException(nameof(newTransaction)); } if (oldTransaction == null) { throw new ArgumentNullException(nameof(oldTransaction)); } TextTransactionMergePolicy oldPolicy = oldTransaction.MergePolicy as TextTransactionMergePolicy; TextTransactionMergePolicy newPolicy = newTransaction.MergePolicy as TextTransactionMergePolicy; if (oldPolicy == null || newPolicy == null) { throw new InvalidOperationException("The MergePolicy for both transactions should be a TextTransactionMergePolicy."); } // Make sure the merge policy directions permit merging these two transactions. if ((oldPolicy._allowableMergeDirections & TextTransactionMergeDirections.Forward) == 0 || (newPolicy._allowableMergeDirections & TextTransactionMergeDirections.Backward) == 0) { return(false); } // Only merge text transactions that have the same description if (!string.Equals(newTransaction.Description, oldTransaction.Description, StringComparison.Ordinal)) { return(false); } // If one of the transactions is empty, than it is safe to merge if ((newTransaction.UndoPrimitives.Count == 0) || (oldTransaction.UndoPrimitives.Count == 0)) { return(true); } // Make sure that we only merge consecutive edits ITextUndoPrimitive newerBeforeTextChangePrimitive = newTransaction.UndoPrimitives[0]; ITextUndoPrimitive olderAfterTextChangePrimitive = oldTransaction.UndoPrimitives[oldTransaction.UndoPrimitives.Count - 1]; return(newerBeforeTextChangePrimitive.CanMerge(olderAfterTextChangePrimitive)); }
public override bool CanMerge(ITextUndoPrimitive older) { if (older == null) { throw new ArgumentNullException(nameof(older)); } AfterTextBufferChangeUndoPrimitive olderPrimitive = older as AfterTextBufferChangeUndoPrimitive; // We can only merge with IUndoPrimitives of AfterTextBufferChangeUndoPrimitive type if (olderPrimitive == null) { return(false); } return(olderPrimitive.State.Matches(this.State)); }
public override bool CanMerge(ITextUndoPrimitive older) { if (older == null) { throw new ArgumentNullException("older"); } AfterTextBufferChangeUndoPrimitive olderPrimitive = older as AfterTextBufferChangeUndoPrimitive; // We can only merge with IUndoPrimitives of AfterTextBufferChangeUndoPrimitive type if (olderPrimitive == null) { return(false); } return((olderPrimitive.CaretIndex == _oldCaretIndex) && (olderPrimitive.CaretVirtualSpace == OldCaretVirtualSpaces)); }
public void AddUndo(ITextUndoPrimitive undo) { }
public ITextUndoPrimitive Merge(ITextUndoPrimitive older) { throw new NotImplementedException(); }
public void AddUndo(ITextUndoPrimitive undo) { _primitiveList.Add(undo); }
public virtual ITextUndoPrimitive Merge(ITextUndoPrimitive older) { throw new System.NotSupportedException(); }
public ITextUndoPrimitive Merge(ITextUndoPrimitive older) { throw new NotSupportedException(); }
public void AddUndo(ITextUndoPrimitive undo) { _innerTransaction.AddUndo(undo); }
public bool CanMerge(ITextUndoPrimitive older) { return(false); }
void ITextUndoTransaction.AddUndo(ITextUndoPrimitive undo) { _primitiveList.Add(undo); }
void ITextUndoTransaction.AddUndo(ITextUndoPrimitive undo) { AddUndo(undo); }
internal void AddUndo(ITextUndoPrimitive undo) { System.Diagnostics.Debug.Assert(undo.CanUndo); _primitiveList.Add(undo); undo.Parent = this; }
public ITextUndoPrimitive Merge(ITextUndoPrimitive primitive) { throw new InvalidOperationException("Strings.DelegatedUndoPrimitiveCannotMerge"); }
public bool CanMerge(ITextUndoPrimitive older) => false;
public bool CanMerge(ITextUndoPrimitive older) { if (older == null) throw new ArgumentNullException(nameof(older)); return false;//TODO: }
public ITextUndoPrimitive Merge(ITextUndoPrimitive older) { if (older == null) throw new ArgumentNullException(nameof(older)); throw new NotSupportedException();//TODO: }
public bool CanMerge(ITextUndoPrimitive older) { return false; }
public bool CanMerge(ITextUndoPrimitive older) => true;
public ITextUndoPrimitive Merge(ITextUndoPrimitive older) => older;
public ITextUndoPrimitive Merge(ITextUndoPrimitive older) { return(older); }
public ITextUndoPrimitive Merge(ITextUndoPrimitive older) { return older; }