GetColumn() public method

public GetColumn ( int position ) : int
position int
return int
コード例 #1
0
        /// <summary>
        /// manages Brace highlighting
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void TextArea_UpdateUI(object sender, UpdateUIEventArgs e)
        {
            // Has the caret changed position?
            var caretPos = TextArea.CurrentPosition;

            if (lastCaretPos != caretPos)
            {
                UpdateStatusEventArgs evt = new UpdateStatusEventArgs();
                evt.Text = "Pos: " + caretPos.ToString();
                FireUpdateStatus(this, evt);
                lastCaretPos = caretPos;
                var bracePos1 = -1;
                var bracePos2 = -1;
                //TODO Brace higligthing not working or overridden by Lexer??
                // Is there a brace to the left or right?
                if (caretPos > 0 && IsBrace(TextArea.GetCharAt(caretPos - 1)))
                {
                    bracePos1 = (caretPos - 1);
                }
                else if (IsBrace(TextArea.GetCharAt(caretPos)))
                {
                    bracePos1 = caretPos;
                }

                if (bracePos1 >= 0)
                {
                    // Find the matching brace
                    bracePos2 = TextArea.BraceMatch(bracePos1);
                    if (bracePos2 == Scintilla.InvalidPosition)
                    {
                        TextArea.BraceBadLight(bracePos1);
                        TextArea.HighlightGuide = 0;
                    }
                    else
                    {
                        TextArea.BraceHighlight(bracePos1, bracePos2);
                        TextArea.HighlightGuide = TextArea.GetColumn(bracePos1);
                    }
                }
                else
                {
                    // Turn off brace matching
                    TextArea.BraceHighlight(Scintilla.InvalidPosition, Scintilla.InvalidPosition);
                    TextArea.HighlightGuide = 0;
                }
            }
        }
コード例 #2
0
        private void FilasYColumnas()
        {
            while (true)
            {
                try
                {
                    this.Invoke((MethodInvoker) delegate
                    {
                        var cu = TextArea.CurrentPosition;
                        var f  = TextArea.CurrentLine;
                        var co = TextArea.GetColumn(cu);

                        filas.Text    = " " + (f + 1);
                        columnas.Text = " " + (co + 1);
                    });
                }
                catch (Exception ex)
                {
                }
            }
        }
コード例 #3
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.XML:

                if (ch == '}' || ch == ')' || ch == ']')
                {
                    int styleBit = getPrevStyle(Scintilla.CurrentPos);
                    if (handleWithCpp(styleBit))
                    {
                        handleCpp(ch, newline);
                    }
                }
                if (ch == newline)
                {
                    int cpos    = Scintilla.CurrentPos;
                    int origPos = cpos;
                    if (Scintilla.EndOfLine.Mode == EndOfLineMode.Crlf)
                    {
                        cpos -= 2;
                    }
                    else
                    {
                        cpos -= 1;
                    }

                    int styleBit = getPrevStyle(cpos);



                    if (handleWithCpp(styleBit))
                    {
                        handleCpp(ch, newline);
                    }
                    else
                    {
                        Line   curLine     = Scintilla.Lines.FromPosition(cpos);
                        string line        = curLine.Text;
                        int    col         = Scintilla.GetColumn(cpos);
                        int    i           = 0;
                        int    openCnt     = 0;
                        int    closeCount  = 0;
                        bool   inTag       = false;
                        string tagName     = "";
                        bool   buildingTag = false;
                        while (i < col && i < line.Length)
                        {
                            if (line[i] == '<')
                            {
                                if (curLine.Length > i)
                                {
                                    if (line[i + 1] != '/' && line[i + 1] != '!')
                                    {
                                        buildingTag = true;
                                        inTag       = true;
                                    }
                                    else
                                    {
                                        closeCount++;
                                        inTag = false;
                                    }
                                }
                            }


                            if (inTag && line[i] != '<')
                            {
                                if (line[i].IsWordChar() && buildingTag)
                                {
                                    tagName += line[i];
                                }

                                if (!line[i].IsWordChar())
                                {
                                    buildingTag = false;
                                }


                                if (line[i] == '>' && inTag)
                                {
                                    if (i > 0)
                                    {
                                        if (line[i - 1] != '/')
                                        {
                                            // Ignore br. May be others to ignore.
                                            if (tagName.ToLowerInvariant() != "br")
                                            {
                                                openCnt++;
                                            }
                                            inTag = false;
                                        }
                                    }
                                }
                            }
                            i++;
                        }

                        if (openCnt > closeCount)
                        {
                            cpos = Scintilla.CurrentPos;
                            string lnBreak = "";
                            if (Scintilla.EndOfLine.Mode == EndOfLineMode.CR)
                            {
                                lnBreak = "\r";
                            }
                            else if (Scintilla.EndOfLine.Mode == EndOfLineMode.LF)
                            {
                                lnBreak = "\n";
                            }
                            else
                            {
                                lnBreak = "\r\n";
                            }
                            Scintilla.UndoRedo.BeginUndoAction();
                            // Grab the current line indent
                            int lineIndent = curLine.Indentation;

                            // add in a line break. This also puts cursor on the next line but only
                            // if auto closing html brackets.
                            if (Scintilla.AutoClose.AutoCloseHtmlTags)
                            {
                                Scintilla.Selection.Text = lnBreak;
                            }

                            // Indent the next line back to the current line.
                            Scintilla.Lines.Current.Indentation = curLine.Indentation;

                            // Jump back to the original position (The new line which we want indented further
                            Scintilla.Selection.Start = origPos;
                            Scintilla.Selection.End   = origPos;

                            // Set indentation.
                            Scintilla.Lines.Current.Indentation = curLine.Indentation + TabWidth;
                            Scintilla.CurrentPos = Scintilla.Lines.Current.EndPosition;
                            Scintilla.UndoRedo.EndUndoAction();
                        }
                        else
                        {
                            // maintain indentation
                            Scintilla.UndoRedo.BeginUndoAction();
                            Scintilla.Lines.Current.Indentation = curLine.Indentation;
                            Scintilla.CurrentPos = Scintilla.Lines.Current.EndPosition;
                            Scintilla.UndoRedo.EndUndoAction();
                        }
                    }
                }
                if (ch == '>')
                {
                    XmlMatchedTagsPos xmlTag = new XmlMatchedTagsPos();
                    if (MatchingTag.getXmlMatchedTagsPos(Scintilla, ref xmlTag, true))
                    {
                        int indentSize = Scintilla.NativeInterface.GetLineIndentation(Scintilla.NativeInterface.LineFromPosition(xmlTag.tagOpenStart));
                        Scintilla.NativeInterface.SetLineIndentation(Scintilla.Lines.Current.Number, indentSize);
                    }
                }
                break;

            case SmartIndent.CPP:
            case SmartIndent.CPP2:
                handleCpp(ch, newline);
                break;
            }
        }