Пример #1
0
        /// <summary>
        /// Create a Side-by-side map for the given snapshot difference. Note that only side-by-side line maps are supported
        /// (character maps -- needed for word wrap -- will require a different approach since even "matches" could have different
        /// lengths if ignore white space is turned on).
        /// </summary>
        public SideBySideMap(ISnapshotDifference difference)
        {
            Requires.NotNull(difference, nameof(difference));
            this.Difference = difference;

            // Calculate the effective document "length" (where the length of each diff block
            // is the maximum of the right & left diffs) and store it for each diff.
            //
            // This code assumes word wrap is off. If it is on, we need to use the characters in each block.
            _sideBySideEndAtDiff = new List <int>(difference.LineDifferences.Differences.Count);

            var leftEnd       = 0;
            var rightEnd      = 0;
            var sideBySideEnd = 0;

            for (int i = 0; (i < difference.LineDifferences.Differences.Count); ++i)
            {
                var diff = difference.LineDifferences.Differences[i];

                int newLeftEnd  = diff.Left.End;
                int newRightEnd = diff.Right.End;

                var leftDelta  = newLeftEnd - leftEnd;
                var rightDelta = newRightEnd - rightEnd;

                sideBySideEnd += Math.Max(leftDelta, rightDelta);
                _sideBySideEndAtDiff.Add(sideBySideEnd);

                leftEnd  = newLeftEnd;
                rightEnd = newRightEnd;
            }

            // Since we're in a match, (current.RightBufferSnapshot.LineCount - rightEnd) == current.LeftBufferSnapshot.LineCount - leftEnd
            this.SideBySideLength = sideBySideEnd + difference.RightBufferSnapshot.LineCount - rightEnd;
        }
 /// <summary>
 /// Create a change event from the given before and after <see cref="ISnapshotDifference"/>s.
 /// </summary>
 /// <param name="before">The <see cref="ISnapshotDifference"/> before the change (may be <c>null</c>).</param>
 /// <param name="after">The <see cref="ISnapshotDifference"/> after the change.</param>
 public SnapshotDifferenceChangeEventArgs(ISnapshotDifference before, ISnapshotDifference after)
 {
     Before = before; After = after;
 }