internal static void InsertText(string insertedText, TextSource ts) { var tb = ts.CurrentTB; try { tb.Selection.BeginUpdate(); char cc = '\x0'; if (ts.Count == 0) { InsertCharCommand.InsertLine(ts); tb.Selection.Start = Place.Empty; } tb.ExpandBlock(tb.Selection.Start.iLine); var len = insertedText.Length; for (int 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(); } }
internal static void ClearSelected(TextSource ts) { var tb = ts.CurrentTB; Place start = tb.Selection.Start; Place end = tb.Selection.End; int fromLine = Math.Min(end.iLine, start.iLine); int toLine = Math.Max(end.iLine, start.iLine); int fromChar = tb.Selection.FromX; int toChar = tb.Selection.ToX; if (fromLine < 0) { return; } // if (fromLine == toLine) { RemoveRange(ts, fromLine, fromChar, toChar); } else { RemoveRange(ts, fromLine, fromChar, ts[fromLine].Count); //ts[fromLine].RemoveRange( fromChar, ts[fromLine].Count - fromChar ); //ts[toLine].RemoveRange( 0, toChar ); RemoveRange(ts, toLine, 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 ClearSelected(TextSource ts) { var tb = ts.CurrentTB; tb.Selection.Normalize(); Place start = tb.Selection.Start; Place end = tb.Selection.End; int fromLine = Math.Min(end.iLine, start.iLine); int toLine = Math.Max(end.iLine, start.iLine); int fromChar = tb.Selection.FromX; int 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); } }
internal static void ClearSelected(TextSource ts) { var tb = ts.CurrentTB; var start = tb.Selection.Start; var end = tb.Selection.End; var fromLine = Math.Min(end.iLine, start.iLine); var toLine = Math.Max(end.iLine, start.iLine); var fromChar = tb.Selection.FromX; var toChar = tb.Selection.ToX; if (fromLine >= 0) { 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.CurrentTB; try { tb.Selection.BeginUpdate(); char cc = '\x0'; if (ts.Count == 0) { InsertCharCommand.InsertLine(ts); tb.Selection.Start = Place.Empty; } tb.ExpandBlock(tb.Selection.Start.iLine); foreach (char c in insertedText) { InsertCharCommand.InsertChar(c, ref cc, ts); } ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1)); } finally { tb.Selection.EndUpdate(); } }
internal static void ClearSelected(FastColoredTextBox tb) { Place start = tb.Selection.Start; Place end = tb.Selection.End; int fromLine = Math.Min(end.iLine, start.iLine); int toLine = Math.Max(end.iLine, start.iLine); int fromChar = tb.Selection.FromX; int toChar = tb.Selection.ToX; if (fromLine < 0) { return; } // if (fromLine == toLine) { tb[fromLine].RemoveRange(fromChar, toChar - fromChar); } else { tb[fromLine].RemoveRange(fromChar, tb[fromLine].Count - fromChar); tb[toLine].RemoveRange(0, toChar); tb.RemoveLine(fromLine + 1, toLine - fromLine - 1); InsertCharCommand.MergeLines(fromLine, tb); } // tb.Selection.Start = new Place(fromChar, fromLine); // tb.needRecalc = true; }
/// <summary> /// Undo operation /// </summary> public override void Undo() { var tb = ts.CurrentTB; ts.OnTextChanging(); var insertedRange = new Range(tb, 0, iLines[0], 0, iLines[iLines.Count - 1] + 1); tb.Selection.BeginUpdate(); //tb.BeginUpdate(); for (int i = 0; i < iLines.Count; i++) { var iLine = iLines[i]; if (iLine < ts.Count) { tb.Selection.Start = new Place(0, iLine); } else { tb.Selection.Start = new Place(ts[ts.Count - 1].Count, ts.Count - 1); } InsertCharCommand.InsertLine(ts); tb.Selection.Start = new Place(0, iLine); var text = prevText[prevText.Count - i - 1]; InsertTextCommand.InsertText(text, ts); ts[iLine].IsChanged = true; if (iLine < ts.Count - 1) { ts[iLine + 1].IsChanged = true; } else { ts[iLine - 1].IsChanged = true; } if (text.Trim() != string.Empty) { ts.OnTextChanged(iLine, iLine); } } //tb.EndUpdate(); tb.Selection.EndUpdate(); tb.OnTextInserted(insertedRange); ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1)); }
/// <summary> /// Undo operation /// </summary> public override void Undo() { var tb = Ts.CurrentTb; Ts.OnTextChanging(); tb.Selection.BeginUpdate(); //tb.BeginUpdate(); for (var i = 0; i < _iLines.Count; i++) { var iLine = _iLines[i]; if (iLine < Ts.Count) { tb.Selection.Start = new Place(0, iLine); } else { tb.Selection.Start = new Place(Ts[Ts.Count - 1].Count, Ts.Count - 1); } InsertCharCommand.InsertLine(Ts); tb.Selection.Start = new Place(0, iLine); var text = _prevText[_prevText.Count - i - 1]; InsertTextCommand.InsertText(text, Ts); Ts[iLine].IsChanged = true; if (iLine < Ts.Count - 1) { Ts[iLine + 1].IsChanged = true; } else { Ts[iLine - 1].IsChanged = true; } if (text.Trim() != string.Empty) { Ts.OnTextChanged(iLine, iLine); } } //tb.EndUpdate(); tb.Selection.EndUpdate(); Ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1)); }
static void RemoveRange(TextSource ts, int fromLine, int fromChar, int toChar) { var tb = ts.CurrentTB; if (tb.AllowTabs) { //InsertCharCommand.DumpLine( ts, fromLine ); // remove backwards to properly handle tabs for (int i = toChar - 1; i >= fromChar;) { char dummy = 'ö'; i -= InsertCharCommand.RemoveChar(ts, fromLine, i, ref dummy); } } else { ts[fromLine].RemoveRange(fromChar, toChar - fromChar); } }
internal static void InsertText(string insertedText, FastColoredTextBox tb) { try { tb.Selection.BeginUpdate(); char cc = '\x0'; if (tb.LinesCount == 0) { InsertCharCommand.InsertLine(tb); } tb.ExpandBlock(tb.Selection.Start.iLine); foreach (char c in insertedText) { InsertCharCommand.InsertChar(c, ref cc, tb); } tb.needRecalc = true; } finally { tb.Selection.EndUpdate(); } }