/// <summary> /// Searches for the given <see cref="CharacterRange"/> in the current results and returns a string describing its index. /// </summary> /// <param name="r"><see cref="CharacterRange"/> of interest.</param> /// <returns>String in the format "i out of N matches".</returns> public string GetIndexString(CharacterRange r) { if ((CurrentResults != null) && (r.cpMax != r.cpMin)) { var index = CurrentResults.BinarySearch(r) + 1; return(index + " out of " + CurrentResults.Count + " matches"); } else { return(string.Empty); } }
void GetResults(TextView view, int start, int length) { CurrentResults.Clear(); if (string.IsNullOrEmpty(textToFind)) { return; } if (string.IsNullOrEmpty(view.Document.Text)) { return; } foreach (Match m in Expr.Matches(view.Document.Text, start)) { CurrentResults.Add(TextRange.FromMatch(m)); } }
public void Draw(TextView textView, DrawingContext drawingContext) { if (textView == null) { throw new ArgumentNullException("textView"); } if (drawingContext == null) { throw new ArgumentNullException("drawingContext"); } if (CurrentResults == null || !textView.VisualLinesValid) { return; } var visualLines = textView.VisualLines; if (visualLines.Count == 0) { return; } var viewStart = visualLines.First().FirstDocumentLine.Offset; var viewEnd = visualLines.Last().LastDocumentLine.EndOffset; foreach (var result in CurrentResults.FindOverlappingSegments(viewStart, viewEnd - viewStart)) { var geoBuilder = new BackgroundGeometryBuilder { //BorderThickness = markerPen != null ? markerPen.Thickness : 0, AlignToWholePixels = true, CornerRadius = 3 }; geoBuilder.AddSegment(textView, result); var geometry = geoBuilder.CreateGeometry(); if (geometry != null) { drawingContext.DrawGeometry(_markerBrush, _markerPen, geometry); } } }