CharAt() public method

public CharAt ( int position ) : char
position int
return char
Ejemplo n.º 1
0
        private void handleCpp(char ch, char newline)
        {
            string lnBreak = "";

            if (Scintilla.EndOfLine.Mode == EndOfLineMode.CR)
            {
                lnBreak = "\r";
            }
            else if (Scintilla.EndOfLine.Mode == EndOfLineMode.LF)
            {
                lnBreak = "\n";
            }
            else
            {
                lnBreak = "\r\n";
            }
            if (ch == newline)
            {
                Line   curLine  = Scintilla.Lines.Current;
                Line   tempLine = curLine;
                int    previousIndent;
                string tempText;

                do
                {
                    tempLine       = tempLine.Previous;
                    previousIndent = tempLine.Indentation;
                    tempText       = tempLine.Text.Trim();
                    if (tempText.Length == 0)
                    {
                        previousIndent = -1;
                    }
                }while ((tempLine.Number > 1) && (previousIndent < 0));

                bool addLineBreak = false;


                Scintilla.Lines.Current.Indentation = previousIndent;

                if (tempText.EndsWith("{") || tempText.EndsWith("(") || tempText.EndsWith("["))
                {
                    if (Scintilla.AutoClose.AutoCloseBraces)
                    {
                        Scintilla.Selection.Text = lnBreak;
                    }
                    int bracePos = Scintilla.CurrentPos - 1;
                    while (bracePos > 0 && Scintilla.CharAt(bracePos) != ch)
                    {
                        bracePos--;
                    }
                    //if (bracePos > 0 && Scintilla.Styles.GetStyleAt(bracePos) == 10)
                    previousIndent += TabWidth;
                }

                curLine.Indentation = previousIndent;

                Scintilla.CurrentPos = curLine.IndentPosition;
            }
            else if (ch == '}' || ch == ']' || ch == ')')
            {
                int  position       = Scintilla.CurrentPos;
                Line curLine        = Scintilla.Lines.Current;
                int  previousIndent = curLine.Previous.Indentation;
                int  match          = Scintilla.SafeBraceMatch(position - 1);
                if (match != -1)
                {
                    previousIndent      = Scintilla.Lines.FromPosition(match).Indentation;
                    curLine.Indentation = previousIndent;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     If Smart Indenting is enabled, this delegate will be added to the CharAdded multicast event.
        /// </summary>
        internal void CheckSmartIndent(char ch)
        {
            char newline = (Scintilla.EndOfLine.Mode == EndOfLineMode.CR) ? '\r' : '\n';

            switch (SmartIndentType)
            {
            case SmartIndent.None:
                return;

            case SmartIndent.Simple:
                if (ch == newline)
                {
                    Line curLine = Scintilla.Lines.Current;
                    curLine.Indentation  = curLine.Previous.Indentation;
                    Scintilla.CurrentPos = curLine.IndentPosition;
                }
                break;

            case SmartIndent.CPP:
            case SmartIndent.CPP2:
                if (ch == newline)
                {
                    Line   curLine  = Scintilla.Lines.Current;
                    Line   tempLine = curLine;
                    int    previousIndent;
                    string tempText;

                    do
                    {
                        tempLine       = tempLine.Previous;
                        previousIndent = tempLine.Indentation;
                        tempText       = tempLine.Text.Trim();
                        if (tempText.Length == 0)
                        {
                            previousIndent = -1;
                        }
                    }while ((tempLine.Number > 1) && (previousIndent < 0));

                    if (tempText.EndsWith("{"))
                    {
                        int bracePos = Scintilla.CurrentPos - 1;
                        while (bracePos > 0 && Scintilla.CharAt(bracePos) != '{')
                        {
                            bracePos--;
                        }
                        if (bracePos > 0 && Scintilla.Styles.GetStyleAt(bracePos) == 10)
                        {
                            previousIndent += TabWidth;
                        }
                    }
                    curLine.Indentation  = previousIndent;
                    Scintilla.CurrentPos = curLine.IndentPosition;
                }
                else if (ch == '}')
                {
                    int  position       = Scintilla.CurrentPos;
                    Line curLine        = Scintilla.Lines.Current;
                    int  previousIndent = curLine.Previous.Indentation;
                    int  match          = Scintilla.SafeBraceMatch(position - 1);
                    if (match != -1)
                    {
                        previousIndent      = Scintilla.Lines.FromPosition(match).Indentation;
                        curLine.Indentation = previousIndent;
                    }
                }
                break;
            }
        }