public override void Undo() { var tb = TextSource.CurrentTextBox; TextSource.OnTextChanging(); tb.Selection.BeginUpdate(); for (var i = 0; i < _iLines.Count; i++) { var iLine = _iLines[i]; tb.Selection.Start = iLine < TextSource.Count ? new Place(0, iLine) : new Place(TextSource[TextSource.Count - 1].Count, TextSource.Count - 1); InsertCharCommand.InsertLine(TextSource); tb.Selection.Start = new Place(0, iLine); var text = _prevText[_prevText.Count - i - 1]; InsertTextCommand.InsertText(text, TextSource); TextSource[iLine].IsChanged = true; if (iLine < TextSource.Count - 1) { TextSource[iLine + 1].IsChanged = true; } else { TextSource[iLine - 1].IsChanged = true; } if (text.Trim() != string.Empty) { TextSource.OnTextChanged(iLine, iLine); } } tb.Selection.EndUpdate(); TextSource.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1)); }
internal static void ClearSelected(TextSource ts) { var tb = ts.CurrentTextBox; var start = tb.Selection.Start; var end = tb.Selection.End; var fromLine = Math.Min(end.Line, start.Line); var toLine = Math.Max(end.Line, start.Line); var fromChar = tb.Selection.FromX; var toChar = tb.Selection.ToX; if (fromLine < 0) { return; } if (fromLine == toLine) { ts[fromLine].RemoveRange(fromChar, toChar - fromChar); } else { ts[fromLine].RemoveRange(fromChar, ts[fromLine].Count - fromChar); ts[toLine].RemoveRange(0, toChar); ts.RemoveLine(fromLine + 1, toLine - fromLine - 1); InsertCharCommand.MergeLines(fromLine, ts); } tb.Selection.Start = new Place(fromChar, fromLine); ts.NeedRecalc(new TextSource.TextChangedEventArgs(fromLine, toLine)); }
internal static void InsertText(string insertedText, TextSource ts) { var tb = ts.CurrentTextBox; try { tb.Selection.BeginUpdate(); var cc = '\x0'; if (ts.Count == 0) { InsertCharCommand.InsertLine(ts); tb.Selection.Start = Place.Empty; } tb.ExpandBlock(tb.Selection.Start.Line); var len = insertedText.Length; for (var i = 0; i < len; i++) { var c = insertedText[i]; if (c == '\r' && (i >= len - 1 || insertedText[i + 1] != '\n')) { InsertCharCommand.InsertChar('\n', ref cc, ts); } else { InsertCharCommand.InsertChar(c, ref cc, ts); } } ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1)); } finally { tb.Selection.EndUpdate(); } }