Example #1
0
        private void UndoModification(Modification modification, ref Point cursorPosition)
        {
            int lineCountToRemove = modification.NewLinesCount;
            if (modification.StartLine + lineCountToRemove > textBufferLineList.Count)
                lineCountToRemove = textBufferLineList.Count - modification.StartLine;

            List<string> linesToRemove = textBufferLineList.GetRange(modification.StartLine, lineCountToRemove);

            if (modification.ActionType == Modification.Action.Insert)
            {
                AddInsertionToRedoGroup(modification.StartLine,
                    modification.OriginalContents.Count, linesToRemove, cursorPosition);
            }
            else if (modification.ActionType == Modification.Action.Remove)
            {
                AddRemoveToRedoGroup(modification.StartLine,
                    modification.OriginalContents.Count, linesToRemove, cursorPosition);
            }

            cursorPosition = modification.CursorPosition;
            textBufferLineList.RemoveRange(modification.StartLine, lineCountToRemove);
            textBufferLineList.InsertRange(modification.StartLine, modification.OriginalContents);
        }
Example #2
0
 internal void Add(Modification modification)
 {
     this.modifications.Add(modification);
 }
Example #3
0
        private void RedoModification(Modification modification, ref Point cursorPosition)
        {
            // If modification is to be done on the line beyond the last, then we are essentially
            // dealing with a non-existence line. In such cases, the "original line contents" (the
            // thing we would like to backup on the undo group) will be an empty line.
            //
            bool modificationBeyondFinalLine = (textBufferLineList.Count == modification.StartLine);

            List<string> originalContents = null;
            if (false != modificationBeyondFinalLine)
            {
                originalContents = new List<string>();
                originalContents.Add(string.Empty);
            }
            else
            {
                // Before we redo the changes, there will be the "original contents" that we
                // would want to backup in the undo group. Store them somewhere safe and then
                // remove the lines from the line list.
                //
                originalContents = textBufferLineList.GetRange(modification.StartLine, modification.NewLinesCount);
            }

            if (modification.ActionType == Modification.Action.Insert)
            {
                RecordInsertionInternal(modification.StartLine,
                    modification.OriginalContents.Count, originalContents, cursorPosition);
            }
            else if (modification.ActionType == Modification.Action.Remove)
            {
                RecordRemovalInternal(modification.StartLine,
                    modification.OriginalContents.Count, originalContents, cursorPosition);
            }

            if (false == modificationBeyondFinalLine)
                textBufferLineList.RemoveRange(modification.StartLine, modification.NewLinesCount);

            textBufferLineList.InsertRange(modification.StartLine, modification.OriginalContents);
            cursorPosition = modification.CursorPosition;
        }