Пример #1
0
        protected override void OnCharAdded(CharAddedEventArgs e)
        {
            int pos = this.CurrentPos;

            if (Context.IsCloseBracket(e.Ch) && e.Ch == this.NativeInterface.GetCharAt(pos))
            {
                this.NativeInterface.CharRight();
                this.NativeInterface.DeleteBack();
            }

            char matchChar = char.MinValue;

            switch (e.Ch)
            {
            case '(':
            {
                if (m_context.IsCommentOrString(CurrentPos) == false)
                {
                    // TODO implement this
                    //CodeComplete();
                }
                matchChar = ')';
                break;
            }

            case '[':
            {
                matchChar = ']';
                break;
            }

            case '{':
            {
                m_context.AutoIndent(e.Ch);
                matchChar = '}';
                break;
            }

            case ':':
            {
                m_context.AutoIndent(e.Ch);
                goto case '.';
            }

            // fall through...
            case '.':
            case '>':
            {
                if (m_context.IsCommentOrString(CurrentPos) == false)
                {
                    //CodeComplete();
                }
                break;
            }

            case '}':
            {
                m_context.AutoIndent(e.Ch);
                break;
            }

            case '\n':
            {
                // in case ENTER was hit immediately after we inserted '{' into the code
                if (m_lastCharAdded == '{' && m_autoAddMatchedBrace)
                {
                    matchChar = '}';
                    InsertText(pos, matchChar.ToString());
                    UndoRedo.BeginUndoAction();
                    NativeInterface.CharRight();

                    m_context.AutoIndent('}');

                    InsertText(pos, Environment.NewLine);

                    NativeInterface.CharRight();
                    SetCaretAt(pos);

                    base.OnCharAdded(e);

                    UndoRedo.EndUndoAction();
                }
                else
                {
                    m_context.AutoIndent(e.Ch);
                }
                break;
            }

            default:
            {
                break;
            }
            }

            if (matchChar != char.MinValue && m_autoAddMatchedBrace && !m_context.IsCommentOrString(pos))
            {
                if (matchChar == ')')
                {
                    // avoid adding close brace if the next char is not a whitespace
                    // character
                    int nextChar = SafeGetChar(pos);
                    switch (nextChar)
                    {
                    case ' ':
                    case '\t':
                    case '\n':
                    case '\r':
                        InsertText(pos, matchChar.ToString());
                        //SetIndicatorCurrent(MATCH_INDICATOR);
                        // use grey colour rather than black, otherwise this indicator is invisible when using the
                        // black theme
                        //NativeInterface.IndicatorFillRange(pos, 1);
                        break;
                    }
                }
                else if (matchChar != '}')
                {
                    InsertText(pos, matchChar.ToString());
                    //SetIndicatorCurrent(MATCH_INDICATOR);
                    // use grey colour rather than black, otherwise this indicator is invisible when using the
                    // black theme
                    //NativeInterface.IndicatorFillRange(pos, 1);
                }
            }

            if (e.Ch != '\r')
            {
                m_lastCharAdded = e.Ch;
            }
        }