Beispiel #1
0
        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;
                }
                }
            }
        }