Пример #1
0
        private ElisionSourceSpansChangedEventArgs ApplySpanChanges(NormalizedSpanCollection spansToElide, NormalizedSpanCollection spansToExpand)
        {
            ElisionSnapshot         beforeSnapshot = this.currentElisionSnapshot;
            FrugalList <TextChange> textChanges;
            ElisionMap newContent = this.content.EditSpans(this.sourceSnapshot, spansToElide, spansToExpand, out textChanges);

            if (newContent != this.content)
            {
                this.content = newContent;
                INormalizedTextChangeCollection normalizedChanges = NormalizedTextChangeCollection.Create(textChanges);
                SetCurrentVersionAndSnapshot(normalizedChanges);
                return(new ElisionSourceSpansChangedEventArgs(beforeSnapshot, this.currentElisionSnapshot,
                                                              spansToElide, spansToExpand, null));
            }
            else
            {
                return(null);
            }
        }
        private void ConstructChanges()
        {
            var diffs = differ.GetDifferences();

            List <TextChange> changes = new List <TextChange>();
            int pos = this.textPosition;

            // each difference generates a text change
            foreach (Difference diff in diffs)
            {
                pos += GetMatchSize(diffs.LeftSequence, diff.Before);
                TextChange change = TextChange.Create(pos,
                                                      BufferFactoryService.StringRebuilderFromSnapshotSpans(diffs.LeftSequence, diff.Left),
                                                      BufferFactoryService.StringRebuilderFromSnapshotSpans(diffs.RightSequence, diff.Right),
                                                      this.currentSnapshot);
                changes.Add(change);
                pos += change.OldLength;
            }
            this.normalizedChanges = NormalizedTextChangeCollection.Create(changes);
        }
Пример #3
0
        private void ConstructChanges()
        {
            IDifferenceCollection <SnapshotSpan> diffs = differ.GetDifferences();

            List <TextChange> changes = new List <TextChange>();
            int pos = this.textPosition;

            // each difference generates a text change
            foreach (Difference diff in diffs)
            {
                pos += GetMatchSize(differ.DeletedSpans, diff.Before);
                TextChange change = new TextChange(pos,
                                                   ReferenceChangeString.CreateChangeString(differ.DeletedSpans, diff.Left),
                                                   ReferenceChangeString.CreateChangeString(differ.InsertedSpans, diff.Right),
                                                   this.currentSnapshot);
                changes.Add(change);
                pos += change.OldLength;
            }
            this.normalizedChanges = NormalizedTextChangeCollection.Create(changes);
        }
Пример #4
0
        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));
        }