internal TextContentChangedEventArgs ApplyReload(StringRebuilder newContent, EditOptions editOptions, object editTag) { // we construct a normalized change list where the inserted text is a reference string that // points "forward" to the next snapshot and whose deleted text is a reference string that points // "backward" to the prior snapshot. This pins both snapshots in memory but that's better than materializing // giant strings, and when (?) we have paging text storage, memory requirements will be minimal. ITextSnapshot oldSnapshot = this.currentSnapshot; StringRebuilder oldContent = BufferFactoryService.StringRebuilderFromSnapshotSpan(new SnapshotSpan(oldSnapshot, 0, oldSnapshot.Length)); TextChange change = TextChange.Create(oldPosition: 0, oldText: oldContent, newText: newContent, currentSnapshot: oldSnapshot); TextVersion newVersion = this.currentVersion.CreateNext(changes: null, newLength: newContent.Length, reiteratedVersionNumber: -1); TextSnapshot newSnapshot = new TextSnapshot(this, newVersion, newContent); this.currentVersion.SetChanges(NormalizedTextChangeCollection.Create(new TextChange[] { change }, editOptions.ComputeMinimalChange ? (StringDifferenceOptions?)editOptions.DifferenceOptions : null, this.textDifferencingService, oldSnapshot, newSnapshot)); this.currentVersion = newVersion; this.builder = newContent; this.currentSnapshot = newSnapshot; return(new TextContentChangedEventArgs(oldSnapshot, newSnapshot, editOptions, editTag)); }
public static ChangeString CreateChangeString(IList <SnapshotSpan> sourceSpans, Span selected) { if (selected.Length == 0) { return(ChangeString.EmptyChangeString); } else if (selected.Length == 1) { return(ReferenceChangeString.CreateChangeString(sourceSpans[selected.Start])); } else { StringRebuilder builder = SimpleStringRebuilder.Create(String.Empty); for (int i = 0; (i < selected.Length); ++i) { builder = builder.Insert(builder.Length, BufferFactoryService.StringRebuilderFromSnapshotSpan(sourceSpans[selected.Start + i])); } return(ReferenceChangeString.CreateChangeString(builder)); } }
public ReferenceChangeString(SnapshotSpan span) : this(BufferFactoryService.StringRebuilderFromSnapshotSpan(span)) { }
private StringRebuilder DeletionChangeString(Span deleteSpan) { return(BufferFactoryService.StringRebuilderFromSnapshotAndSpan(this.originSnapshot, deleteSpan)); }