Example #1
0
        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
                // Extra tab program

                int space_count = 0;
                int length      = tb.Selection.Start.iChar;

                for (int cnt = -1; cnt >= -1 * length; cnt--)
                {
                    char a = ts[tb.Selection.Start.iLine][tb.Selection.End.iChar + cnt].c;
                    if (a != ' ')
                    {
                        break;
                    }
                    space_count++;
                }
                if (space_count > 1)
                {
                    int max = (space_count - 1) % 4;
                    for (int cnt = 0; cnt < max; cnt++)
                    {
                        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);
                    }
                }

                // Extra End
                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;
                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;
            }
        }
Example #2
0
 public SelectCommand(TextSource ts) : base(ts)
 {
 }
Example #3
0
 /// <summary>
 /// Construstor
 /// </summary>
 /// <param name="tb">Underlaying textbox</param>
 public ClearSelectedCommand(TextSource ts) : base(ts)
 {
 }
Example #4
0
 /// <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;
 }
Example #5
0
 /// <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;
 }
Example #6
0
        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;
            }
        }