/// <summary> /// Constructor /// </summary> /// <param name="tb">Underlaying textbox</param> /// <param name="insertedText">Text for inserting</param> public InsertTextCommand(TextSource ts, string insertedText) : base(ts) { this.insertedText = insertedText; }
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 (char)1: 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 { int tl = tb.TabLength; deletedChar = ts[tb.Selection.Start.iLine][tb.Selection.Start.iChar - 1].c; do { ts[tb.Selection.Start.iLine].RemoveAt(tb.Selection.Start.iChar - 1); tb.Selection.Start = new Place(tb.Selection.Start.iChar + (c == (char)1 ? 0 : -1), tb.Selection.Start.iLine); tl--; if (c == (char)1 && tb.Selection.Start.iChar > 0 && tb.Selection.Start.iChar >= ts[tb.Selection.Start.iLine].Count) { tb.Selection.Start = new Place(tb.Selection.Start.iChar - 1, tb.Selection.Start.iLine); break; } if (deletedChar != ' ' || tb.Selection.Start.iChar == 0) { if (c == (char)1 && tb.Selection.Start.iChar > 0) { tb.Selection.Start = new Place(tb.Selection.Start.iChar - 1, tb.Selection.Start.iLine); } break; } deletedChar = ts[tb.Selection.Start.iLine][tb.Selection.Start.iChar - 1].c; if ((deletedChar != ' ' || tl == 0) && c == (char)1 && tb.Selection.Start.iChar > 0) { tb.Selection.Start = new Place(tb.Selection.Start.iChar - 1, tb.Selection.Start.iLine); } } while (deletedChar == ' ' && tl > 0); } break; case '\t': for (int i = 0; i < tb.TabLength; i++) { ts[tb.Selection.Start.iLine].Insert(tb.Selection.Start.iChar, new Char(' ')); } tb.Selection.Start = new Place(tb.Selection.Start.iChar + tb.TabLength, 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; } }
/// <summary> /// Constructor /// </summary> /// <param name="tb">Underlaying textbox</param> /// <param name="c">Inserting char</param> public InsertCharCommand(TextSource ts, char c) : base(ts) { this.c = c; }