コード例 #1
0
        public override TextRange GetNextWord()
        {
            TextExtent currentWord = GetTextExtent(CurrentPosition);

            if (currentWord.Span.End < _textBuffer.AdvancedTextBuffer.CurrentSnapshot.Length)
            {
                // If the current point is at the end of the line, look for the next word on the next line
                if ((CurrentPosition == EndOfLine) && (CurrentPosition != _textBuffer.AdvancedTextBuffer.CurrentSnapshot.Length))
                {
                    TextPoint textPoint = Clone();
                    textPoint.MoveToBeginningOfNextLine();
                    textPoint.MoveTo(textPoint.StartOfLine);
                    TextExtent wordOnNextLine = GetTextExtent(textPoint.CurrentPosition);
                    if (wordOnNextLine.IsSignificant)
                    {
                        return(textPoint.GetCurrentWord());
                    }
                    else if (wordOnNextLine.Span.End >= textPoint.EndOfLine)
                    {
                        return(textPoint.GetTextRange(textPoint.EndOfLine));
                    }
                    return(textPoint.GetNextWord());
                }
                // By default, VS stops at line breaks when determing word
                // boundaries.
                else if (ShouldStopAtEndOfLine(currentWord.Span.End) || IsCurrentWordABlankLine(currentWord))
                {
                    return(GetTextRange(currentWord.Span.End));
                }

                TextExtent nextWord = GetTextExtent(currentWord.Span.End);

                if (!nextWord.IsSignificant)
                {
                    nextWord = GetTextExtent(nextWord.Span.End);
                }

                int start = nextWord.Span.Start;
                int end   = nextWord.Span.End;

                // The text structure navigator can return a word with whitespace attached at the end.
                // Handle that case here.
                start = Math.Max(start, currentWord.Span.End);

                TextPoint startPoint = Clone();
                TextPoint endPoint   = Clone();
                startPoint.MoveTo(start);
                endPoint.MoveTo(end);

                return(_bufferPrimitivesFactory.CreateTextRange(_textBuffer, startPoint, endPoint));
            }

            return(_bufferPrimitivesFactory.CreateTextRange(_textBuffer, TextBuffer.GetEndPoint(), TextBuffer.GetEndPoint()));
        }
コード例 #2
0
 public override TextRange GetNextWord()
 {
     return(_bufferPoint.GetNextWord());
 }