Example #1
0
        private static IReadOnlyList <ImmutableArray <TextChangeRange> > GetChangesBetween(
            SourceText oldText,
            ChangedText newText
            )
        {
            var list = new List <ImmutableArray <TextChangeRange> >();

            ChangeInfo?change = newText._info;

            list.Add(change.ChangeRanges);

            while (change != null)
            {
                SourceText?actualOldText;
                change.WeakOldText.TryGetTarget(out actualOldText);

                if (actualOldText == oldText)
                {
                    return(list);
                }

                change = change.Previous;
                if (change != null)
                {
                    list.Insert(0, change.ChangeRanges);
                }
            }

            // did not find old text, so not connected?
            list.Clear();
            return(list);
        }
Example #2
0
        public override SourceText WithChanges(IEnumerable <TextChange> changes)
        {
            // compute changes against newText to avoid capturing strong references to this ChangedText instance.
            // _newText will only ever be one of CompositeText, SubText, StringText or LargeText, so calling WithChanges on it
            // will either produce a ChangeText instance or the original instance in case of a empty change.
            ChangedText changed = _newText.WithChanges(changes) as ChangedText;

            if (changed != null)
            {
                return(new ChangedText(this, changed._newText, changed._info.ChangeRanges));
            }
            else
            {
                // change was empty, so just return this same instance
                return(this);
            }
        }
Example #3
0
        private static IReadOnlyList<ImmutableArray<TextChangeRange>> GetChangesBetween(SourceText oldText, ChangedText newText)
        {
            var list = new List<ImmutableArray<TextChangeRange>>();

            var change = newText._info;
            list.Add(change.ChangeRanges);

            while (change != null)
            {
                SourceText actualOldText;
                change.WeakOldText.TryGetTarget(out actualOldText);

                if (actualOldText == oldText)
                {
                    return list;
                }

                change = change.Previous;
                if (change != null)
                {
                    list.Insert(0, change.ChangeRanges);
                }
            }

            // did not find old text, so not connected?
            list.Clear();
            return list;
        }
Example #4
0
 public static ImmutableArray <TextChangeRange> Merge(ImmutableArray <TextChangeRange> oldChanges, ImmutableArray <TextChangeRange> newChanges)
 => ChangedText.Merge(oldChanges, newChanges);