private static IHighlightingHandler MakeSelectionInplaceHighlightingHander( SelectionInfo selection, MessageTextGetter displayTextGetter, IWordSelection wordSelection, int cacheSize) { IHighlightingHandler newHandler = null; if (selection?.IsSingleLine == true) { var normSelection = selection.Normalize(); var text = displayTextGetter(normSelection.First.Message); var line = text.GetNthTextLine(normSelection.First.TextLineIndex); int beginIdx = normSelection.First.LineCharIndex; int endIdx = normSelection.Last.LineCharIndex; var selectedPart = line.SubString(beginIdx, endIdx - beginIdx); if (selectedPart.Any(c => !char.IsWhiteSpace(c))) { var options = new Search.Options() { Template = selectedPart, MessageTextGetter = displayTextGetter, }; var optionsPreprocessed = options.BeginSearch(); newHandler = new CachingHighlightingHandler(msg => GetSelectionHighlightingRanges(msg, optionsPreprocessed, wordSelection, (normSelection.First.Message, beginIdx + line.StartIndex - text.Text.StartIndex)), cacheSize); } } return(newHandler); }
private void DoInplaceHighlighting( IMessage msg, PointF location, StringSlice text, int lineBegin, int lineEnd, IHighlightingHandler handler, Brush brush) { if (handler != null) { foreach (var hlRange in handler.GetHighlightingRanges(msg)) { int?hlBegin = null; int?hlEnd = null; if (hlRange.Item1 >= lineBegin && hlRange.Item1 <= lineEnd) { hlBegin = hlRange.Item1; } if (hlRange.Item2 >= lineBegin && hlRange.Item2 <= lineEnd) { hlEnd = hlRange.Item2; } if (hlBegin != null || hlEnd != null) { var tmp = DrawingUtils.GetLineSubstringBounds( text.SubString(lineBegin, lineEnd - lineBegin).Value, hlBegin.GetValueOrDefault(lineBegin) - lineBegin, hlEnd.GetValueOrDefault(lineEnd) - lineBegin, ctx.Canvas, ctx.Font, ctx.TextFormat, m.MessageRect, location.X); tmp.Inflate(0, -1); if (brush == null) { var cl = hlRange.Item3.GetBackgroundColor(); if (cl != null) { using (var tmpBrush = new Brush(cl.Value.ToColor())) { FillInplaceHightlightRectangle(ctx, tmp, tmpBrush); } } } else { FillInplaceHightlightRectangle(ctx, tmp, brush); } } } } }
void UpdateSelectionInplaceHighlightingFields() { IHighlightingHandler newHandler = null; if (selection.IsSingleLine) { var normSelection = selection.Normalize(); var line = GetTextToDisplay(normSelection.First.Message).GetNthTextLine(normSelection.First.TextLineIndex); int beginIdx = normSelection.First.LineCharIndex; int endIdx = normSelection.Last.LineCharIndex; if (wordSelection.IsWordBoundary(line, beginIdx, endIdx)) { var selectedPart = line.SubString(beginIdx, endIdx - beginIdx); if (wordSelection.IsWord(selectedPart)) { var options = new Search.Options() { Template = selectedPart, SearchInRawText = presentationDataAccess.ShowRawMessages, }; var optionsPreprocessed = options.BeginSearch(); newHandler = new HighlightingHandler(optionsPreprocessed, wordSelection); } } } if ((selectionInplaceHighlightingHandler != null) != (newHandler != null)) { view.Invalidate(); } else if (newHandler != null) { view.Invalidate(); } selectionInplaceHighlightingHandler = newHandler; }