Esempio n. 1
0
        private static void DoHighlight(CodeTextBox ctb)
        {
            int caretpos = ctb.SelectionStart;//put it back to this

            int startchar = 0;//limit rehighlighting everything
            for (int i = 1; i < ctb.lastlinesdone.Length && i < ctb.Lines.Length &&
                (ctb.lastlinesdone[i] == ctb.Lines[i].Length); ++i)
            {//firstline should be left at the first line that's different
                startchar += (ctb.Lines[i - 1].Length + newlinelen); //newline
            }

            //command is a temp(?) hack to highlight commands
            bool quotesel = false, command = false, startline = true;
            int newselpos = 0;
            for (int i = startchar; i < ctb.Text.Length; ++i)
            {
                switch (ctb.Text[i])
                {
                    case _newline:
                        quotesel = command = false;
                        startline = true;
                        break;
                    case _quote:
                        if (command)
                        {
                            ctb.Highlight(newselpos, (i - newselpos), ctb.ColorCommand);
                            command = false;
                        }
                        else if (quotesel) { ctb.Highlight(newselpos, (i - newselpos) + 1, ctb.ColorString);}
                        else if (!quotesel) { newselpos = i; }
                        quotesel = !quotesel;
                        startline = false;
                        break;
                    case _space:
                        if (!startline)//starting spaces
                        {
                            if (command)
                            {
                                ctb.Highlight(newselpos, (i - newselpos), ctb.ColorCommand);
                                command = false;
                            }
                        }
                        break;
                    case _rightparen://0 arg command ends here
                        if (command)
                        {
                            ctb.Highlight(newselpos, (i - newselpos), ctb.ColorCommand);
                            command = false;
                        }
                        break;
                    case _comma:
                        if (!startline)//starting spaces
                        {
                            if (command)
                            {
                                ctb.Highlight(newselpos, (i - newselpos), ctb.ColorCommand);
                                command = false;
                            }
                        }
                        break;
                    case _leftparen://temphack to skip ( at start of line
                        if (!startline)//same as space essentially
                        {
                            if (command)
                            {
                                ctb.Highlight(newselpos, (i - newselpos), ctb.ColorCommand);
                                command = false;
                            }
                        }
                        break;
                    default:
                        if (startline && !command)
                        {
                            newselpos = i;
                            command = true;
                            startline = false;
                        }
                        break;
                }
            }
            ctb.DeselectAll();
            ctb.SelectionStart = caretpos;
        }
Esempio n. 2
0
        private static void DoHighlight(CodeTextBox ctb)
        {
            int caretpos = ctb.SelectionStart;//put it back to this


            int startchar = 0;//limit rehighlighting everything

            for (int i = 1; i < ctb.lastlinesdone.Length && i < ctb.Lines.Length &&
                 (ctb.lastlinesdone[i] == ctb.Lines[i].Length); ++i)
            {                                                        //firstline should be left at the first line that's different
                startchar += (ctb.Lines[i - 1].Length + newlinelen); //newline
            }


            //command is a temp(?) hack to highlight commands
            bool quotesel = false, command = false, startline = true;
            int  newselpos = 0;

            for (int i = startchar; i < ctb.Text.Length; ++i)
            {
                switch (ctb.Text[i])
                {
                case _newline:
                    quotesel  = command = false;
                    startline = true;
                    break;

                case _quote:
                    if (command)
                    {
                        ctb.Highlight(newselpos, (i - newselpos), ctb.ColorCommand);
                        command = false;
                    }
                    else if (quotesel)
                    {
                        ctb.Highlight(newselpos, (i - newselpos) + 1, ctb.ColorString);
                    }
                    else if (!quotesel)
                    {
                        newselpos = i;
                    }
                    quotesel  = !quotesel;
                    startline = false;
                    break;

                case _space:
                    if (!startline)    //starting spaces
                    {
                        if (command)
                        {
                            ctb.Highlight(newselpos, (i - newselpos), ctb.ColorCommand);
                            command = false;
                        }
                    }
                    break;

                case _rightparen:    //0 arg command ends here
                    if (command)
                    {
                        ctb.Highlight(newselpos, (i - newselpos), ctb.ColorCommand);
                        command = false;
                    }
                    break;

                case _comma:
                    if (!startline)    //starting spaces
                    {
                        if (command)
                        {
                            ctb.Highlight(newselpos, (i - newselpos), ctb.ColorCommand);
                            command = false;
                        }
                    }
                    break;

                case _leftparen:    //temphack to skip ( at start of line
                    if (!startline) //same as space essentially
                    {
                        if (command)
                        {
                            ctb.Highlight(newselpos, (i - newselpos), ctb.ColorCommand);
                            command = false;
                        }
                    }
                    break;

                default:
                    if (startline && !command)
                    {
                        newselpos = i;
                        command   = true;
                        startline = false;
                    }
                    break;
                }
            }
            ctb.DeselectAll();
            ctb.SelectionStart = caretpos;
        }