static private InsertText ( string insertedText, TextSource ts ) : void | ||
insertedText | string | |
ts | TextSource | |
Результат | void |
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();
}
}
/// <summary> /// Execute operation /// </summary> public override void Execute() { var tb = ts.CurrentTB; prevText.Clear(); ts.OnTextChanging(ref insertedText); tb.Selection.BeginUpdate(); tb.BeginUpdate(); for (int i = ranges.Count - 1; i >= 0; i--) { tb.Selection.Start = ranges[i].Start; tb.Selection.End = ranges[i].End; prevText.Add(tb.Selection.Text); ClearSelected(ts); if (insertedText != "") { InsertTextCommand.InsertText(insertedText, ts); } } if (ranges.Count > 0) { ts.OnTextChanged(ranges[0].Start.iLine, ranges[ranges.Count - 1].End.iLine); } tb.EndUpdate(); tb.Selection.EndUpdate(); ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1)); lastSel = new RangeInfo(tb.Selection); }