private void AddExtraPatchHighlighting()
        {
            var document = TextEditor.Document;
            var markerStrategy = document.MarkerStrategy;

            for (var line = 0; line + 3 < document.TotalNumberOfLines; line++)
            {
                var lineSegment1 = document.GetLineSegment(line);
                var lineSegment2 = document.GetLineSegment(line + 1);
                var lineSegment3 = document.GetLineSegment(line + 2);
                var lineSegment4 = document.GetLineSegment(line + 3);

                if (document.GetCharAt(lineSegment1.Offset) != ' ' ||
                    document.GetCharAt(lineSegment2.Offset) != '-' ||
                    document.GetCharAt(lineSegment3.Offset) != '+' ||
                    (lineSegment4.Length > 0 && document.GetCharAt(lineSegment4.Offset) != ' ')) //fix for issue 173
                    continue;

                var beginOffset = 0;
                var endOffset = lineSegment3.Length;
                var reverseOffset = 0;

                for (; beginOffset < endOffset; beginOffset++)
                {
                    if (!document.GetCharAt(lineSegment3.Offset + beginOffset).Equals('+') &&
                        !document.GetCharAt(lineSegment2.Offset + beginOffset).Equals('-') &&
                        !document.GetCharAt(lineSegment3.Offset + beginOffset).Equals(
                            document.GetCharAt(lineSegment2.Offset + beginOffset)))
                        break;
                }

                for (; endOffset > beginOffset; endOffset--)
                {
                    reverseOffset = lineSegment3.Length - endOffset;

                    if (!document.GetCharAt(lineSegment3.Offset + lineSegment3.Length - 1 - reverseOffset)
                             .Equals('+') &&
                        !document.GetCharAt(lineSegment2.Offset + lineSegment2.Length - 1 - reverseOffset)
                             .Equals('-') &&
                        !document.GetCharAt(lineSegment3.Offset + lineSegment3.Length - 1 - reverseOffset).
                             Equals(document.GetCharAt(lineSegment2.Offset + lineSegment2.Length - 1 -
                                                       reverseOffset)))
                        break;
                }

                Color color;
                if (lineSegment3.Length - beginOffset - reverseOffset > 0)
                {
                    color = Settings.DiffAddedExtraColor;
                    markerStrategy.AddMarker(new TextMarker(lineSegment3.Offset + beginOffset,
                                                            lineSegment3.Length - beginOffset - reverseOffset,
                                                            TextMarkerType.SolidBlock, color,
                                                            ColorHelper.GetForeColorForBackColor(color)));
                }

                if (lineSegment2.Length - beginOffset - reverseOffset > 0)
                {
                    color = Settings.DiffRemovedExtraColor;
                    markerStrategy.AddMarker(new TextMarker(lineSegment2.Offset + beginOffset,
                                                            lineSegment2.Length - beginOffset - reverseOffset,
                                                            TextMarkerType.SolidBlock, color,
                                                            ColorHelper.GetForeColorForBackColor(color)));
                }
            }
        }
        public void AddPatchHighlighting()
        {
            var document = TextEditor.Document;
            var markerStrategy = document.MarkerStrategy;
            markerStrategy.RemoveAll(m => true);
            bool forceAbort = false;

            AddExtraPatchHighlighting();

            for (var line = 0; line < document.TotalNumberOfLines && !forceAbort; line++)
            {
                var lineSegment = document.GetLineSegment(line);

                if (lineSegment.TotalLength == 0)
                    continue;

                if (line == document.TotalNumberOfLines - 1)
                    forceAbort = true;

                if (document.GetCharAt(lineSegment.Offset) == '+')
                {
                    var color = Settings.DiffAddedColor;
                    var endLine = document.GetLineSegment(line);

                    for (; line < document.TotalNumberOfLines && document.GetCharAt(endLine.Offset) == '+'; line++)
                    {
                        endLine = document.GetLineSegment(line);
                    }
                    line--;
                    line--;
                    endLine = document.GetLineSegment(line);

                    markerStrategy.AddMarker(new TextMarker(lineSegment.Offset,
                                                            (endLine.Offset + endLine.TotalLength) -
                                                            lineSegment.Offset, TextMarkerType.SolidBlock, color,
                                                            ColorHelper.GetForeColorForBackColor(color)));
                }
                if (document.GetCharAt(lineSegment.Offset) == '-')
                {
                    var color = Settings.DiffRemovedColor;
                    var endLine = document.GetLineSegment(line);

                    for (; line < document.TotalNumberOfLines && document.GetCharAt(endLine.Offset) == '-'; line++)
                    {
                        endLine = document.GetLineSegment(line);
                    }
                    line--;
                    line--;
                    endLine = document.GetLineSegment(line);

                    markerStrategy.AddMarker(new TextMarker(lineSegment.Offset,
                                                            (endLine.Offset + endLine.TotalLength) -
                                                            lineSegment.Offset, TextMarkerType.SolidBlock, color,
                                                            ColorHelper.GetForeColorForBackColor(color)));
                }
                if (document.GetCharAt(lineSegment.Offset) == '@')
                {
                    var color = Settings.DiffSectionColor;
                    var endLine = document.GetLineSegment(line);

                    for (; line < document.TotalNumberOfLines && document.GetCharAt(endLine.Offset) == '@'; line++)
                    {
                        endLine = document.GetLineSegment(line);
                    }
                    line--;
                    line--;
                    endLine = document.GetLineSegment(line);

                    markerStrategy.AddMarker(new TextMarker(lineSegment.Offset,
                                                            (endLine.Offset + endLine.TotalLength) -
                                                            lineSegment.Offset, TextMarkerType.SolidBlock, color,
                                                            ColorHelper.GetForeColorForBackColor(color)));
                }
            }
        }