private static void MarkRange(IMarkerRender render, int start, int len, Color color) { var range = new TextSegment() { StartOffset = start, Length = len, }; render.DrawMarker(range, color); }
public static void MarkDifferenceForSection(Section minusSection, Section plusSection, IMarkerRender markerRender, ITextSource doc, IDiffer differ) { var minusText = doc.GetText(minusSection.Start, minusSection.LenWithEol); var plusText = doc.GetText(plusSection.Start, plusSection.LenWithEol).Replace("\n+", "\n-"); if (plusText.StartsWith("+")) { plusText = "-" + plusText.Remove(0, 1); } var diffsForPlusSection = differ.GetDiffs(minusText, plusText); var pos4Minus = minusSection.Start; var pos4Plus = plusSection.Start; foreach (var diff in diffsForPlusSection) { switch (diff.operation) { case Operation.EQUAL: { pos4Minus += diff.text.Length; pos4Plus += diff.text.Length; break; } case Operation.DELETE: { MarkRange(markerRender, pos4Minus, diff.text.Length, MinusLineMarkerColor); pos4Minus += diff.text.Length; break; } case Operation.INSERT: { MarkRange(markerRender, pos4Plus, diff.text.Length, PlusLineMarkerColor); pos4Plus += diff.text.Length; break; } } } }
private void AddMarkerForDifferences(IMarkerRender markerRender, ITextSource textSource) { if (!_minusLinesSections.Any()) { return; } if (!_plusLinesSections.Any()) { return; } var intersections = HighlighterHelper.GetIntersections(_minusLinesSections, _plusLinesSections); foreach (var intersection in intersections) { HighlighterHelper.MarkDifferenceForSection(intersection.Item1, intersection.Item2, markerRender, textSource, Differ); } }
private static void HighlightSections(IEnumerable <Section> sections, Color color, IMarkerRender markerRender) { foreach (var section in sections) { var range = new TextSegment() { StartOffset = section.Start, EndOffset = section.End, Length = section.End - section.Start + 1, }; markerRender.DrawMarker(range, color); } }
private void HighlightLinesBackground(IMarkerRender markerRender) { HighlightSections(_minusLinesSections, HighlighterHelper.MinusLineColor, markerRender); HighlightSections(_plusLinesSections, HighlighterHelper.PlusLineColor, markerRender); HighlightSections(_headers, HighlighterHelper.HeaderLineColor, markerRender); }