Exemple #1
0
        public override TextRange GetTextRange(TextPoint startPoint, TextPoint endPoint)
        {
            if (startPoint == null)
            {
                throw new ArgumentNullException("startPoint");
            }
            if (endPoint == null)
            {
                throw new ArgumentNullException("endPoint");
            }

            if (!object.ReferenceEquals(startPoint.TextBuffer, this))
            {
                throw new ArgumentException(Strings.TextPointFromWrongBuffer);
            }

            if (!object.ReferenceEquals(endPoint.TextBuffer, this))
            {
                throw new ArgumentException(Strings.TextPointFromWrongBuffer);
            }

            return(_bufferPrimitivesFactory.CreateTextRange(this, startPoint, endPoint));
        }
        public override TextRange GetCurrentWord()
        {
            // If the line is blank, just return a blank range for the line
            SnapshotPoint     currentPoint = AdvancedTextPoint;
            ITextSnapshotLine line         = currentPoint.GetContainingLine();

            if (currentPoint == line.Start && line.Length == 0)
            {
                return(_bufferPrimitivesFactory.CreateTextRange(_textBuffer, this, this));
            }

            TextExtent textExtent = GetTextExtent(CurrentPosition);

            // If the word is not significant, then see if there is a significant word right before this one,
            // and return that instead to mimic VS 9 behavior.
            if (!textExtent.IsSignificant)
            {
                if ((textExtent.Span.Start > 0) && (textExtent.Span.Length > 0))
                {
                    if (textExtent.Span.Start == CurrentPosition)
                    {
                        if (!char.IsWhiteSpace(_textBuffer.AdvancedTextBuffer.CurrentSnapshot[textExtent.Span.Start - 1]))
                        {
                            textExtent = GetTextExtent(textExtent.Span.Start - 1);
                        }
                    }
                    else if (CurrentPosition == EndOfLine)
                    {
                        // If this text point is on the end of the line, then check to see if there is a word
                        // just before the whitespace.
                        if (!char.IsWhiteSpace(_textBuffer.AdvancedTextBuffer.CurrentSnapshot[textExtent.Span.Start - 1]))
                        {
                            TextExtent newExtent = new TextExtent(GetTextExtent(textExtent.Span.Start - 1));
                            textExtent = new TextExtent(new SnapshotSpan(newExtent.Span.Start, textExtent.Span.End), true);
                        }
                    }
                }
            }

            TextPoint startPoint = Clone();

            startPoint.MoveTo(textExtent.Span.Start);
            TextPoint endPoint = Clone();

            endPoint.MoveTo(textExtent.Span.End);

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