コード例 #1
0
ファイル: SearchService.cs プロジェクト: 331564533/dnSpy
		SnapshotSpan? FindNextResultCore(FindOptions options, SnapshotPoint startingPosition) {
			if (SearchString.Length == 0)
				return null;
			var snapshot = wpfTextView.TextSnapshot;
			startingPosition = startingPosition.TranslateTo(snapshot, PointTrackingMode.Negative);
			var searchRange = new SnapshotSpan(snapshot, 0, snapshot.Length);
			try {
				return textSearchService2.Find(searchRange, startingPosition, SearchString, options);
			}
			catch (ArgumentException) when ((options & FindOptions.UseRegularExpressions) != 0) {
				// Invalid regex string
				return null;
			}
		}
コード例 #2
0
        private void FilterImpl(string searchPattern)
        {
            var snapshot   = _textBuffer.CurrentSnapshot;
            var entrySpans = _history.GetAllHistoryEntrySpans();

            Debug.Assert(entrySpans.Any());

            var spansToShow = new List <Span>();
            var spansToHide = new List <Span>();

            var span     = entrySpans[0];
            var showSpan = _textSearchService.Find(span, span.Start, searchPattern, FindOptions.Multiline).HasValue;

            for (var i = 1; i < entrySpans.Count; i++)
            {
                var nextSpan     = entrySpans[i];
                var showNextSpan = _textSearchService.Find(nextSpan, nextSpan.Start, searchPattern, FindOptions.Multiline).HasValue;
                if (showNextSpan)
                {
                    if (showSpan)
                    {
                        span = new SnapshotSpan(span.Start, nextSpan.End);
                    }
                    else if (spansToShow.Any())
                    {
                        spansToHide.Add(span);
                        span = new SnapshotSpan(span.End, nextSpan.End);
                    }
                    else
                    {
                        spansToHide.Add(new SnapshotSpan(span.Start, nextSpan.Start));
                        span = nextSpan;
                    }
                    showSpan = true;
                }
                else
                {
                    if (!showSpan)
                    {
                        span = new SnapshotSpan(span.Start, nextSpan.End);
                    }
                    else
                    {
                        spansToShow.Add(span);
                        span = new SnapshotSpan(span.End, nextSpan.End);
                    }
                    showSpan = false;
                }
            }

            // Add last span
            if (showSpan)
            {
                spansToShow.Add(span);
            }
            else
            {
                spansToHide.Add(span);
            }

            if (spansToShow.Count == 0)
            {
                if (_elisionBuffer.CurrentSnapshot.Length == 0)
                {
                    return;
                }

                _elisionBuffer.ModifySpans(new NormalizedSpanCollection(new Span(0, snapshot.Length)), new NormalizedSpanCollection(new Span(0, 0)));
                return;
            }

            _elisionBuffer.ExpandSpans(new NormalizedSpanCollection(new Span(0, snapshot.Length)));

            MoveCaretToVisiblePoint(spansToShow, snapshot);

            if (spansToHide.Count != 0)
            {
                _elisionBuffer.ElideSpans(new NormalizedSpanCollection(spansToHide));
            }

            _textView.Caret.EnsureVisible();
        }