/// <summary> /// Merge lines i and i+1 /// </summary> internal static void MergeLines(int i, TextSource ts) { var tb = ts.CurrentTB; if (i + 1 >= ts.Count) { return; } tb.ExpandBlock(i); tb.ExpandBlock(i + 1); int pos = ts[i].Count; // if (ts[i].Count == 0) { ts.RemoveLine(i); } else if (ts[i + 1].Count == 0) { ts.RemoveLine(i + 1); } else { ts[i].AddRange(ts[i + 1]); ts.RemoveLine(i + 1); } tb.Selection.Start = new Place(pos, i); ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1)); }
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 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; 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 InsertLine(TextSource ts) { var tb = ts.CurrentTB; if (!tb.Multiline && tb.LinesCount > 0) { return; } if (ts.Count == 0) { ts.InsertLine(0, ts.CreateLine()); } else { BreakLines(tb.Selection.Start.iLine, tb.Selection.Start.iChar, ts); } tb.Selection.Start = new Place(0, tb.Selection.Start.iLine + 1); ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1)); }
/// <summary> /// Merge lines i and i+1 /// </summary> internal static void MergeLines(int i, TextSource ts) { var tb = ts.CurrentTB; if (i + 1 >= ts.Count) { return; } tb.ExpandBlock(i); tb.ExpandBlock(i + 1); int pos = ts[i].Count; // /* * if(ts[i].Count == 0) * ts.RemoveLine(i); * else*/ if (ts[i + 1].Count == 0) { ts.RemoveLine(i + 1); } else { if (tb.AllowTabs) { string deTabbed = ts[i + 1].ToText(0); ts[i].AddTabified(deTabbed); } else { ts[i].AddRange(ts[i + 1]); } ts.RemoveLine(i + 1); } tb.Selection.Start = new Place(pos, i); ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1)); }