Ejemplo n.º 1
0
        int FindWordStart(Document.Document document, int offset)
        {
            LineSegment line = document.GetLineSegmentForOffset(offset);

            if (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset - 1)) && Char.IsWhiteSpace(document.GetCharAt(offset)))
            {
                while (offset > line.Offset && Char.IsWhiteSpace(document.GetCharAt(offset - 1)))
                {
                    --offset;
                }
            }
            else if (IsSelectableChar(document.GetCharAt(offset)) || (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset)) && IsSelectableChar(document.GetCharAt(offset - 1))))
            {
                while (offset > line.Offset && IsSelectableChar(document.GetCharAt(offset - 1)))
                {
                    --offset;
                }
            }
            else
            {
                if (offset > 0 && !Char.IsWhiteSpace(document.GetCharAt(offset - 1)) && !IsSelectableChar(document.GetCharAt(offset - 1)))
                {
                    return(Math.Max(0, offset - 1));
                }
            }
            return(offset);
        }
        // go back to the start of the word we are on
        // if we are already at the start of a word or if we are in whitespace, then go back
        // to the start of the previous word
        public static int FindPrevWordStart(Document document, int offset)
        {
            int originalOffset = offset;

            if (offset > 0)
            {
                LineSegment   line = document.GetLineSegmentForOffset(offset);
                CharacterType t    = GetCharacterType(document.GetCharAt(offset - 1));
                while (offset > line.Offset && GetCharacterType(document.GetCharAt(offset - 1)) == t)
                {
                    --offset;
                }

                // if we were in whitespace, and now we're at the end of a word or operator, go back to the beginning of it
                if (t == CharacterType.WhiteSpace && offset > line.Offset)
                {
                    t = GetCharacterType(document.GetCharAt(offset - 1));
                    while (offset > line.Offset && GetCharacterType(document.GetCharAt(offset - 1)) == t)
                    {
                        --offset;
                    }
                }
            }

            return(offset);
        }
Ejemplo n.º 3
0
        int FindNext(Document.Document document, int offset, char ch)
        {
            LineSegment line   = document.GetLineSegmentForOffset(offset);
            int         endPos = line.Offset + line.Length;

            while (offset < endPos && document.GetCharAt(offset) != ch)
            {
                ++offset;
            }
            return(offset);
        }
        public static int FindWordStart(Document document, int offset)
        {
            LineSegment line       = document.GetLineSegmentForOffset(offset);
            int         lineOffset = line.Offset;

            while (offset > lineOffset && IsLetterDigitOrUnderscore(document.GetCharAt(offset - 1)))
            {
                --offset;
            }

            return(offset);
        }
        public static int FindWordEnd(Document document, int offset)
        {
            LineSegment line   = document.GetLineSegmentForOffset(offset);
            int         endPos = line.Offset + line.Length;

            while (offset < endPos && IsLetterDigitOrUnderscore(document.GetCharAt(offset)))
            {
                ++offset;
            }

            return(offset);
        }
        // go forward to the start of the next word
        // if the cursor is at the start or in the middle of a word we move to the end of the word
        // and then past any whitespace that follows it
        // if the cursor is at the start or in the middle of some whitespace we move to the start of the
        // next word
        public static int FindNextWordStart(Document document, int offset)
        {
            int         originalOffset = offset;
            LineSegment line           = document.GetLineSegmentForOffset(offset);
            int         endPos         = line.Offset + line.Length;
            // lets go to the end of the word, whitespace or operator
            CharacterType t = GetCharacterType(document.GetCharAt(offset));

            while (offset < endPos && GetCharacterType(document.GetCharAt(offset)) == t)
            {
                ++offset;
            }

            // now we're at the end of the word, lets find the start of the next one by skipping whitespace
            while (offset < endPos && GetCharacterType(document.GetCharAt(offset)) == CharacterType.WhiteSpace)
            {
                ++offset;
            }

            return(offset);
        }
Ejemplo n.º 7
0
        int FindWordEnd(Document.Document document, int offset)
        {
            LineSegment line = document.GetLineSegmentForOffset(offset);

            if (line.Length == 0)
            {
                return(offset);
            }
            int endPos = line.Offset + line.Length;

            offset = Math.Min(offset, endPos - 1);

            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);
        }