Exemple #1
0
        public static int FindWordEnd(SD.Document.IDocument document, int offset)
        {
            SD.Document.LineSegment line = document.GetLineSegmentForOffset(offset);
            int endPos = line.Offset + line.Length;

            if (offset == endPos)
            {
                return(offset);
            }

            if (IsSelectableChar(document.GetCharAt(offset)))
            {
                while (offset < endPos && IsSelectableChar(document.GetCharAt(offset)))
                {
                    ++offset;
                }
            }
            else if (Char.IsWhiteSpace(document.GetCharAt(offset)))
            {
                if (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset - 1)))
                {
                    while (offset < endPos && Char.IsWhiteSpace(document.GetCharAt(offset)))
                    {
                        ++offset;
                    }
                }
            }
            else
            {
                return(Math.Max(0, offset + 1));
            }

            return(offset);
        }
        public bool CaretOffsetChanged()
        {
            bool closeDataProvider = textArea.Caret.Offset <= initialOffset;
            int  brackets          = 0;

            if (!closeDataProvider)
            {
                bool insideChar   = false;
                bool insideString = false;
                for (int offset = initialOffset; offset < Math.Min(textArea.Caret.Offset, document.TextLength); ++offset)
                {
                    char ch = document.GetCharAt(offset);
                    switch (ch)
                    {
                    case '\'':
                        insideChar = !insideChar;
                        break;

                    case '[':
                        if (!(insideChar || insideString))
                        {
                            ++brackets;
                        }
                        break;

                    case ']':
                        if (!(insideChar || insideString))
                        {
                            --brackets;
                        }
                        if (brackets <= 0)
                        {
                            return(true);
                        }
                        break;

                    case '(':
                        if (!(insideChar || insideString))
                        {
                            ++brackets;
                        }
                        break;

                    case ')':
                        if (!(insideChar || insideString))
                        {
                            --brackets;
                        }
                        if (brackets <= 0)
                        {
                            return(true);
                        }
                        break;

                    case ';':
                        if (!(insideChar || insideString))
                        {
                            return(true);
                        }
                        break;
                    }
                }
            }

            return(closeDataProvider);
        }