private TextRange FindMatch(string pattern, FindOptions findOptions, TextPoint endPoint)
        {
            if (pattern.Length == 0)
            {
                return(_bufferPrimitivesFactory.CreateTextRange(_textBuffer, this.Clone(), this.Clone()));
            }

            FindData findData = new FindData(pattern, _textBuffer.AdvancedTextBuffer.CurrentSnapshot);

            findData.FindOptions = findOptions;

            bool wrapAround = endPoint == null;

            bool searchReverse = ((findData.FindOptions & FindOptions.SearchReverse) == FindOptions.SearchReverse);

            // In the case of a wrap-around search, we can start the search at this point always.  In the case
            // where we are searching a range in reverse, we have to start at the end point.
            int searchStartPosition = (searchReverse && !wrapAround) ? endPoint.CurrentPosition : CurrentPosition;

            SnapshotSpan?snapshotSpan = _findLogic.FindNext(searchStartPosition, wrapAround, findData);

            if (snapshotSpan.HasValue)
            {
                if ((endPoint == null) || (snapshotSpan.Value.End <= endPoint.CurrentPosition))
                {
                    return(_bufferPrimitivesFactory.CreateTextRange(_textBuffer,
                                                                    _bufferPrimitivesFactory.CreateTextPoint(_textBuffer, snapshotSpan.Value.Start),
                                                                    _bufferPrimitivesFactory.CreateTextPoint(_textBuffer, snapshotSpan.Value.End)));
                }
            }

            return(_bufferPrimitivesFactory.CreateTextRange(_textBuffer, this.Clone(), this.Clone()));
        }
Пример #2
0
 public override TextPoint GetTextPoint(int position)
 {
     if ((position < 0) || (position > _textBuffer.CurrentSnapshot.Length))
     {
         throw new ArgumentOutOfRangeException("position");
     }
     return(_bufferPrimitivesFactory.CreateTextPoint(this, position));
 }