private void UndoTyping(UndoRedoOperation operation) { Doc[operation.StartLine].Text = Doc[operation.StartLine].Text.Remove(operation.StartChar, operation.EndChar - operation.StartChar); this.Viewer.Caret.MoveToPos(operation.StartLine, operation.StartChar, true); if (!string.IsNullOrEmpty(operation.PreviousText)) { EditingController.PasteText(operation.PreviousText); } }
public void ProcessEnterKey() { SaveCurrentOperationToStack(); var operation = new UndoRedoOperation { Type = UndoRedoOperationType.CaretReturn, StartLine = Viewer.Caret.Line, StartChar = Viewer.Caret.Char, EndLine = Viewer.Caret.Line, EndChar = Viewer.Caret.Char, Text = "\r\n" }; Operations.Push(operation); }
private UndoRedoOperation TakeCurrentTypingOperation() { UndoRedoOperation operation; string text = Doc.GetText(CurrentStartLine, CurrentStartChar, CurrentEndLine, CurrentEndChar); operation = new UndoRedoOperation { StartLine = CurrentStartLine, StartChar = CurrentStartChar, EndLine = CurrentEndLine, EndChar = CurrentEndChar, Text = text, Type = UndoRedoOperationType.Insert, PreviousText = PreviousText }; return(operation); }
public void ProcessPaste(int startLine, int startChar, string text, string previousText) { SaveCurrentOperationToStack(); var operation = new UndoRedoOperation { Type = UndoRedoOperationType.Paste, StartLine = startLine, StartChar = startChar, Text = text, EndLine = Caret.Line, EndChar = Caret.Char, PreviousText = previousText, }; Operations.Push(operation); StartNewUndoRedoOperation(); }
public void ProcessDeletion(bool backward) { SaveCurrentOperationToStack(); var start = Viewer.GetSelectionBoundary(true); var end = Viewer.GetSelectionBoundary(false); var operation = new UndoRedoOperation { Type = UndoRedoOperationType.Remove, StartLine = start.Line, StartChar = start.Char, EndLine = end.Line, EndChar = end.Char, }; if (!Viewer.SelectionExists) { if (backward) { operation.Text = Viewer.Caret.Char > 0 ? Doc[Viewer.Caret.Line].Text[Viewer.Caret.Char - 1].ToString() : "\r\n"; } else { if (Viewer.Caret.Char < Doc[Viewer.Caret.Line].Text.Length) { operation.Text = Doc[Viewer.Caret.Line].Text[Viewer.Caret.Char].ToString(); } else { operation.Text = "\r\n"; } } } else { operation.Text = Viewer.SelectionText; } Operations.Push(operation); }