示例#1
0
        public ElisionMap IncorporateChanges(INormalizedTextChangeCollection sourceChanges,
                                             FrugalList <TextChange> projectedChanges,
                                             ITextSnapshot beforeSourceSnapshot,
                                             ITextSnapshot sourceSnapshot,
                                             ITextSnapshot beforeElisionSnapshot)
        {
            ElisionMapNode newRoot = this.root;
            int            accumulatedProjectedDelta = 0;

            foreach (ITextChange sourceChange in sourceChanges)
            {
                int             accumulatedDelete = 0;
                int             incrementalAccumulatedProjectedDelta = 0;
                StringRebuilder newText = TextChange.NewStringRebuilder(sourceChange);

                newRoot = newRoot.IncorporateChange(beforeSourceSnapshot: beforeSourceSnapshot,
                                                    afterSourceSnapshot: sourceSnapshot,
                                                    beforeElisionSnapshot: beforeElisionSnapshot,
                                                    sourceInsertionPosition: sourceChange.NewLength > 0 ? sourceChange.NewPosition : (int?)null,
                                                    newText: newText,
                                                    sourceDeletionSpan: new Span(sourceChange.NewPosition, sourceChange.OldLength),
                                                    absoluteSourceOldPosition: sourceChange.OldPosition,
                                                    absoluteSourceNewPosition: sourceChange.NewPosition,
                                                    projectedPrefixSize: 0,
                                                    projectedChanges: projectedChanges,
                                                    incomingAccumulatedDelta: accumulatedProjectedDelta,
                                                    outgoingAccumulatedDelta: ref incrementalAccumulatedProjectedDelta,
                                                    accumulatedDelete: ref accumulatedDelete);
                accumulatedProjectedDelta += incrementalAccumulatedProjectedDelta;
            }
            if (newRoot.TotalSourceSize != sourceSnapshot.Length)
            {
                Debug.Fail(String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                         "Change incorporation length inconsistency. Elision:{0} Source:{1}", newRoot.TotalSourceSize, sourceSnapshot.Length));
                throw new InvalidOperationException(Strings.InvalidLengthCalculation);
            }
            if (newRoot.TotalSourceLineBreakCount + 1 != sourceSnapshot.LineCount)
            {
                Debug.Fail(String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                         "Change incorporation line count inconsistency. Elision:{0} Source:{1}", newRoot.TotalSourceLineBreakCount + 1, sourceSnapshot.LineCount));
                throw new InvalidOperationException(Strings.InvalidLineCountCalculation);
            }
            return(new ElisionMap(newRoot, this.spanCount));
        }