Пример #1
0
        public ConflictRange GetConflictAfter(int offset)
        {
            for (int i = 0; i < conflictRanges.Count; i++)
            {
                ConflictRange range = conflictRanges[i];

                if (range.StartLineIndex < offset)
                {
                    continue;
                }

                return(i == conflictRanges.Count - 1 ? conflictRanges[0] : conflictRanges[i + 1]);
            }

            return(conflictRanges.Count == 0 ? null : conflictRanges[conflictRanges.Count - 1]);
        }
Пример #2
0
        public ConflictRange GetConflictBefore(int lineNum)
        {
            for (int i = 0; i < conflictRanges.Count; i++)
            {
                ConflictRange range = conflictRanges[i];

                if (range.StartLineIndex < lineNum)
                {
                    continue;
                }

                return(i == 0 ? conflictRanges[conflictRanges.Count - 1] : conflictRanges[i - 1]);
            }

            return(conflictRanges.Count == 0 ? null : conflictRanges[0]);
        }
Пример #3
0
 public bool IsLineInConflict(int lineIndex, out ConflictRange conflictRange)
 {
     foreach (ConflictRange range in conflictRanges)
     {
         if (range.StartLineIndex > lineIndex || range.EndLineIndex <= lineIndex)
         {
             continue;
         }
         if (range.StartLineIndex <= lineIndex && range.EndLineIndex > lineIndex)
         {
             conflictRange = range;
             return(true);
         }
     }
     conflictRange = new ConflictRange();
     return(false);
 }
Пример #4
0
        internal void MergeOutput(VisualDiffOutput otherOutput, ChangeType thisChangeType, ChangeType otherChangeType)
        {
            string[] thisTempLines  = LinesToStringArray(this.RightLines);
            string[] otherTempLines = LinesToStringArray(otherOutput.RightLines);

            this.LeftLines.Clear();
            this.RightLines.Clear();

            Diff diff = new Diff(thisTempLines, otherTempLines, true, true);

            // loop through parts of the diff
            foreach (Diff.Hunk hunk in diff)
            {
                int lineMismatch = hunk.Right.Start - hunk.Left.Start;
                if (hunk.Same)
                {
                    for (int i = hunk.Right.Start; i <= hunk.Right.End; i++)
                    {
                        if (otherOutput.RightLines[i].Change != ChangeType.None)
                        {
                            //Both the user and template have changed to the same thing. Need to display this.
                            leftLines.Add(new DiffLine(otherOutput.LeftLines[i].Text, thisChangeType | otherChangeType, otherOutput.LeftLines[i].IsVirtual));
                            rightLines.Add(new DiffLine(otherTempLines[i], thisChangeType | otherChangeType));
                        }
                        else
                        {
                            leftLines.Add(new DiffLine(otherTempLines[i]));
                            rightLines.Add(new DiffLine(otherTempLines[i]));
                        }
                    }
                }
                else
                {
                    // If the left and right of the hunk both have lines, this could be a conflict.
                    if (hunk.Right.Count != 0 && hunk.Left.Count != 0)
                    {
                        ConflictRange conflictRange = new ConflictRange();
                        conflictRange.StartLineIndex = leftLines.Count;

                        for (int i = hunk.Right.Start; i <= hunk.Right.End; i++)
                        {
                            leftLines.Add(new DiffLine(otherTempLines[i], otherChangeType));
                            rightLines.Add(new DiffLine("", otherChangeType, true));
                        }
                        for (int i = hunk.Left.Start; i <= hunk.Left.End; i++)
                        {
                            leftLines.Add(new DiffLine(thisTempLines[i], thisChangeType));
                            rightLines.Add(new DiffLine("", thisChangeType, true));
                        }

                        conflictRange.EndLineIndex = leftLines.Count;
                        conflictRanges.Add(conflictRange);
                    }
                    else if (hunk.Right.Count != 0)
                    {
                        for (int i = hunk.Right.Start; i <= hunk.Right.End; i++)
                        {
                            leftLines.Add(new DiffLine("", otherChangeType, true));
                            rightLines.Add(new DiffLine(otherTempLines[i], otherChangeType));
                        }
                    }
                    else
                    {
                        for (int i = hunk.Left.Start; i <= hunk.Left.End; i++)
                        {
                            leftLines.Add(new DiffLine("", thisChangeType, true));
                            rightLines.Add(new DiffLine(thisTempLines[i], thisChangeType));
                        }
                    }
                }
            }
        }
Пример #5
0
        internal void MergeOutput(VisualDiffOutput otherOutput, ChangeType thisChangeType, ChangeType otherChangeType)
        {
            string[] thisTempLines = LinesToStringArray(this.RightLines);
            string[] otherTempLines = LinesToStringArray(otherOutput.RightLines);

            this.LeftLines.Clear();
            this.RightLines.Clear();

            Diff diff = new Diff(thisTempLines, otherTempLines, true, true);

            // loop through parts of the diff
            foreach (Diff.Hunk hunk in diff)
            {
                int lineMismatch = hunk.Right.Start - hunk.Left.Start;
                if (hunk.Same)
                {
                    for (int i = hunk.Right.Start; i <= hunk.Right.End; i++)
                    {
                        if (otherOutput.RightLines[i].Change != ChangeType.None)
                        {
                            //Both the user and template have changed to the same thing. Need to display this.
                            leftLines.Add(new DiffLine(otherOutput.LeftLines[i].Text, thisChangeType | otherChangeType, otherOutput.LeftLines[i].IsVirtual));
                            rightLines.Add(new DiffLine(otherTempLines[i], thisChangeType | otherChangeType));
                        }
                        else
                        {
                            leftLines.Add(new DiffLine(otherTempLines[i]));
                            rightLines.Add(new DiffLine(otherTempLines[i]));
                        }
                    }
                }
                else
                {
                    // If the left and right of the hunk both have lines, this could be a conflict.
                    if (hunk.Right.Count != 0 && hunk.Left.Count != 0)
                    {
                        ConflictRange conflictRange = new ConflictRange();
                        conflictRange.StartLineIndex = leftLines.Count;

                        for (int i = hunk.Right.Start; i <= hunk.Right.End; i++)
                        {
                            leftLines.Add(new DiffLine(otherTempLines[i], otherChangeType));
                            rightLines.Add(new DiffLine("", otherChangeType, true));
                        }
                        for (int i = hunk.Left.Start; i <= hunk.Left.End; i++)
                        {
                            leftLines.Add(new DiffLine(thisTempLines[i], thisChangeType));
                            rightLines.Add(new DiffLine("", thisChangeType, true));
                        }

                        conflictRange.EndLineIndex = leftLines.Count;
                        conflictRanges.Add(conflictRange);
                    }
                    else if (hunk.Right.Count != 0)
                    {
                        for (int i = hunk.Right.Start; i <= hunk.Right.End; i++)
                        {
                            leftLines.Add(new DiffLine("", otherChangeType, true));
                            rightLines.Add(new DiffLine(otherTempLines[i], otherChangeType));
                        }
                    }
                    else
                    {
                        for (int i = hunk.Left.Start; i <= hunk.Left.End; i++)
                        {
                            leftLines.Add(new DiffLine("", thisChangeType, true));
                            rightLines.Add(new DiffLine(thisTempLines[i], thisChangeType));
                        }
                    }

                }
            }
        }
Пример #6
0
 public bool IsLineInConflict(int lineIndex, out ConflictRange conflictRange)
 {
     foreach (ConflictRange range in conflictRanges)
     {
         if (range.StartLineIndex > lineIndex || range.EndLineIndex <= lineIndex)
             continue;
         if (range.StartLineIndex <= lineIndex && range.EndLineIndex > lineIndex)
         {
             conflictRange = range;
             return true;
         }
     }
     conflictRange = new ConflictRange();
     return false;
 }