private TextContentChangedEventRaiser IncorporateChanges() { Debug.Assert(this.sourceSnapshot == this.pendingContentChangedEventArgs[0].Before); FrugalList <TextChange> projectedChanges = new FrugalList <TextChange>(); var args0 = this.pendingContentChangedEventArgs[0]; INormalizedTextChangeCollection sourceChanges; // Separate the easy and common case: if (this.pendingContentChangedEventArgs.Count == 1) { sourceChanges = args0.Changes; this.sourceSnapshot = args0.After; } else { // there is more than one snapshot of the source buffer to deal with. Since the changes may be // interleaved by position, we need to get a normalized list in sequence. First we denormalize the // changes so they are all relative to the same single starting snapshot, then we normalize them again into // a single list. // This relies crucially on the fact that we know something about the multiple snapshots: they were // induced by projection span adjustments, and the changes across them are independent. That is to say, // it is not the case that text inserted in one snapshot is deleted in a later snapshot in the series. DumpPendingContentChangedEventArgs(); List <TextChange> denormalizedChanges = new List <TextChange>() { new TextChange(int.MaxValue, StringRebuilder.Empty, StringRebuilder.Empty, LineBreakBoundaryConditions.None) }; for (int a = 0; a < this.pendingContentChangedEventArgs.Count; ++a) { NormalizedTextChangeCollection.Denormalize(this.pendingContentChangedEventArgs[a].Changes, denormalizedChanges); } DumpPendingChanges(new List <Tuple <ITextBuffer, List <TextChange> > >() { new Tuple <ITextBuffer, List <TextChange> >(this.sourceBuffer, denormalizedChanges) }); FrugalList <TextChange> slicedChanges = new FrugalList <TextChange>(); // remove the sentinel for (int d = 0; d < denormalizedChanges.Count - 1; ++d) { slicedChanges.Add(denormalizedChanges[d]); } sourceChanges = NormalizedTextChangeCollection.Create(slicedChanges); this.sourceSnapshot = this.pendingContentChangedEventArgs[this.pendingContentChangedEventArgs.Count - 1].After; } if (sourceChanges.Count > 0) { this.content = this.content.IncorporateChanges(sourceChanges, projectedChanges, args0.Before, this.sourceSnapshot, this.currentElisionSnapshot); } this.pendingContentChangedEventArgs.Clear(); ElisionSnapshot beforeSnapshot = this.currentElisionSnapshot; SetCurrentVersionAndSnapshot(NormalizedTextChangeCollection.Create(projectedChanges)); this.editApplicationInProgress = false; return(new TextContentChangedEventRaiser(beforeSnapshot, this.currentElisionSnapshot, args0.Options, args0.EditTag)); }