Esempio n. 1
0
 internal static void InsertText(string insertedText, QText tb)
 {
     try
     {
         tb.Selection.BeginUpdate();
         char cc = '\x0';
         if (tb.LinesCount == 0)
             InsertCharCommand.InsertLine(tb);
         tb.ExpandBlock(tb.Selection.Start.iLine);
         foreach (char c in insertedText)
             InsertCharCommand.InsertChar(c, ref cc, tb);
         tb.needRecalc = true;
     }
     finally
     {
         tb.Selection.EndUpdate();
     }
 }
Esempio n. 2
0
 internal static void InsertChar(char c, ref char deletedChar, QText tb)
 {
     switch (c)
     {
         case '\n':
             if (tb.LinesCount == 0) InsertLine(tb);
             InsertLine(tb);
             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 (tb[tb.Selection.Start.iLine - 1].VisibleState != VisibleState.Visible) tb.ExpandBlock(tb.Selection.Start.iLine - 1);
                 deletedChar = '\n';
                 MergeLines(tb.Selection.Start.iLine - 1, tb);
             }
             else
             {
                 deletedChar = tb[tb.Selection.Start.iLine][tb.Selection.Start.iChar - 1].c;
                 tb[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;
         default:
             tb[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;
     }
 }
Esempio n. 3
0
        internal static void MergeLines(int i, QText tb)
        {
            if (i + 1 >= tb.LinesCount) return;

            tb.ExpandBlock(i);
            tb.ExpandBlock(i + 1);
            int pos = tb[i].Count;
            //
            if (tb[i].Count == 0)
                tb.RemoveLine(i);
            else
                if (tb[i + 1].Count == 0)
                    tb.RemoveLine(i + 1);
                else
                {
                    tb[i].AddRange(tb[i + 1]);
                    tb.RemoveLine(i + 1);
                }
            tb.Selection.Start = new Place(pos, i);
            tb.needRecalc = true;
        }