internal void CloseUndoGroup() { if (null != currentUndoGroup) { undoStack.Add(currentUndoGroup); currentUndoGroup = null; } }
internal void Undo(ref Point cursorPosition) { CloseUndoGroup(); if (undoStack.Count == 0) return; ModificationGroup topMostGroup = undoStack[undoStack.Count - 1]; topMostGroup.ReverseModifications(); foreach (Modification modification in topMostGroup.List) UndoModification(modification, ref cursorPosition); // Redo group is always closed immediately. if (null != currentRedoGroup) { redoStack.Add(currentRedoGroup); currentRedoGroup = null; } undoStack.RemoveAt(undoStack.Count - 1); }
private void RecordInsertionInternal(int lineInsertedAt, int newLineCount, List<string> originalContents, Point cursorPosition) { if (currentUndoGroup == null) currentUndoGroup = new ModificationGroup(); if (currentUndoGroup.ModificationCount == 1) { Modification lastModification = currentUndoGroup.GetLastModification(); if (null != lastModification && (false != lastModification.IsInsertion) && lastModification.StartLine == lineInsertedAt) return; // Insertions after another insertion are ignored. } currentUndoGroup.Add(new Modification(lineInsertedAt, newLineCount, originalContents, Modification.Action.Insert, cursorPosition)); }
private void RecordRemovalInternal(int lineRemovedAt, int lineCount, List<string> originalContents, Point cursorPosition) { if (currentUndoGroup == null) currentUndoGroup = new ModificationGroup(); else { Modification lastModification = currentUndoGroup.GetLastModification(); if (null != lastModification) { if (false != lastModification.IsRemoval) return; if (false != lastModification.IsInsertion) { CloseUndoGroup(); currentUndoGroup = new ModificationGroup(); } } } currentUndoGroup.Add(new Modification(lineRemovedAt, lineCount, originalContents, Modification.Action.Remove, cursorPosition)); }
private void AddRemoveToRedoGroup(int lineInsertedAt, int newLineCount, List<string> originalContents, Point cursorPosition) { if (currentRedoGroup == null) currentRedoGroup = new ModificationGroup(); currentRedoGroup.Add(new Modification(lineInsertedAt, newLineCount, originalContents, Modification.Action.Remove, cursorPosition)); }