public void CreateTags(IEnumerable <UI.ViewModel.MatchNode> matches) { using (m_storage.Update()) { m_storage.RemoveTagSpans(s => true); if (matches == null) { return; } var snapshot = m_buffer.CurrentSnapshot; foreach (var match in matches) { var matchInfo = new MatchInfo(match.Index); foreach (var group in match.Groups) { if (group.Number == 0) { continue; } if (!group.Success) { continue; } var groupInfo = new GroupInfo(matchInfo, group.Index, group.Number, group.Name); foreach (var capture in group.Captures) { var captureInfo = new CaptureInfo(groupInfo, capture.Index); if (capture.Segment != null && 0 < capture.Segment.Length && snapshot.TryCreateTrackingSpan(capture.Segment.Start, capture.Segment.Length, out var span)) { // we do not add group with index 0 so it is better to adjust indices var classificationType = GetGroupClassificationType(captureInfo.Parent.Index - 1); m_storage.CreateTagSpan(span, new CaptureTag(captureInfo, classificationType)); } } } } m_storage.PinSnapshot(snapshot); } }
public void Hightlight(Int32 start, Int32 length) { using (m_storage.Update()) { m_storage.RemoveTagSpans(s => true); if (m_view.TextBuffer.CurrentSnapshot.TryCreateTrackingSpan(start, length, out var span)) { if (length == 0) { var textHeightAbove = m_view.FormattedLineSource.TextHeightAboveBaseline; var textHeightBelow = m_view.FormattedLineSource.TextHeightBelowBaseline; var columnWidth = m_view.FormattedLineSource.ColumnWidth; var lineHeight = m_view.FormattedLineSource.LineHeight; var adornment = CreateAdornment(columnWidth, lineHeight); SetLayoutOptions(adornment); adornment.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); m_storage.CreateTagSpan(span, new IntraTextAdornmentTag( adornment, null, 0, textHeightAbove, 0, //textHeightAbove + textHeightBelow, 0, PositionAffinity.Predecessor)); } else { m_storage.CreateTagSpan(span, new HightlightTag()); } } } }