internal static void InsertChar(char c, ref char deletedChar, TextSource ts)
{
var tb = ts.CurrentTB;
switch (c)
{
case '\n':
if (!ts.CurrentTB.AllowInsertRemoveLines)
throw new ArgumentOutOfRangeException("Cant insert this char in ColumnRange mode");
if (ts.Count == 0)
InsertLine(ts);
InsertLine(ts);
break;
case '\r': break;
case '\b'://backspace
if (tb.Selection.Start.iChar == 0 && tb.Selection.Start.iLine == 0)
return;
if (tb.Selection.Start.iChar == 0)
{
if (!ts.CurrentTB.AllowInsertRemoveLines)
throw new ArgumentOutOfRangeException("Cant insert this char in ColumnRange mode");
if (tb.LineInfos[tb.Selection.Start.iLine - 1].VisibleState != VisibleState.Visible)
tb.ExpandBlock(tb.Selection.Start.iLine - 1);
deletedChar = '\n';
MergeLines(tb.Selection.Start.iLine - 1, ts);
}
else
{
deletedChar = ts[tb.Selection.Start.iLine][tb.Selection.Start.iChar - 1].c;
ts[tb.Selection.Start.iLine].RemoveAt(tb.Selection.Start.iChar - 1);
tb.Selection.Start = new Place(tb.Selection.Start.iChar - 1, tb.Selection.Start.iLine);
}
break;
case '\t':
int spaceCountNextTabStop = tb.TabLength - (tb.Selection.Start.iChar % tb.TabLength);
if (spaceCountNextTabStop == 0)
spaceCountNextTabStop = tb.TabLength;
for (int i = 0; i < spaceCountNextTabStop; i++)
ts[tb.Selection.Start.iLine].Insert(tb.Selection.Start.iChar, new Char(' '));
tb.Selection.Start = new Place(tb.Selection.Start.iChar + spaceCountNextTabStop, tb.Selection.Start.iLine);
break;
default:
ts[tb.Selection.Start.iLine].Insert(tb.Selection.Start.iChar, new Char(c));
tb.Selection.Start = new Place(tb.Selection.Start.iChar + 1, tb.Selection.Start.iLine);
break;
}
}