Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void RedoTextEditing(ref Point cursorPosition)
        {
            int lineIndex = -1, affectedLines = -1;
            int startLineCount = lineList.Count;

            ModificationGroup modifications = undoRedoRecorder.GetTopMostRedoGroup();

            if (null == modifications)
            {
                return;
            }

            Modification modification = modifications.GetLastModification();

            if (null != modification)
            {
                lineIndex     = modification.StartLine;
                affectedLines = modification.OriginalContents.Count;
            }

            undoRedoRecorder.Redo(ref cursorPosition);
            ArrangeTextBuffer();

            if (null != LinesUpdated)
            {
                // Notify listeners of line changes.
                int deltaLines = lineList.Count - startLineCount;
                LinesUpdated(this, new LinesUpdateEventArgs(lineIndex, affectedLines, deltaLines));
            }
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
 internal void CloseUndoGroup()
 {
     if (null != currentUndoGroup)
     {
         undoStack.Add(currentUndoGroup);
         currentUndoGroup = null;
     }
 }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        internal void Redo(ref Point cursorPosition)
        {
            if (redoStack.Count == 0)
            {
                return;
            }

            CloseUndoGroup();

            ModificationGroup topMostGroup = redoStack[redoStack.Count - 1];

            topMostGroup.ReverseModifications();

            foreach (Modification modification in topMostGroup.List)
            {
                RedoModification(modification, ref cursorPosition);
            }

            CloseUndoGroup();
            redoStack.RemoveAt(redoStack.Count - 1);
        }