/// <summary>
 /// Construstor
 /// </summary>
 /// <param name="ts">The ts.</param>
 public ClearSelectedCommand(TextSource ts) : base(ts)
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ts">The ts.</param>
 /// <param name="c">Inserting char</param>
 public InsertCharCommand(TextSource ts, char c) : base(ts)
 {
     this.c = c;
 }
        /// <summary>
        /// Inserts the character.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <param name="deletedChar">The deleted character.</param>
        /// <param name="ts">The ts.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// Cant insert this char in ColumnRange mode
        /// or
        /// Cant insert this char in ColumnRange mode
        /// </exception>
        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;
            }
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ts">The ts.</param>
 /// <param name="insertedText">Text for inserting</param>
 public InsertTextCommand(TextSource ts, string insertedText) : base(ts)
 {
     this.InsertedText = insertedText;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SelectCommand"/> class.
 /// </summary>
 /// <param name="ts">The ts.</param>
 public SelectCommand(TextSource ts) : base(ts)
 {
 }