public WeakEventHookForBufferGraph(BufferGraph targetGraph, ITextBuffer sourceBuffer) { _targetGraph = new WeakReference <BufferGraph>(targetGraph); _sourceBuffer = sourceBuffer; sourceBuffer.ContentTypeChanged += OnSourceBufferContentTypeChanged; ProjectionBuffer projectionBuffer = sourceBuffer as ProjectionBuffer; if (projectionBuffer != null) { projectionBuffer.SourceBuffersChangedImmediate += OnSourceBuffersChanged; } }
public void UnsubscribeFromSourceBuffer() { if (_sourceBuffer != null) { _sourceBuffer.ContentTypeChanged -= OnSourceBufferContentTypeChanged; ProjectionBuffer projectionBuffer = _sourceBuffer as ProjectionBuffer; if (projectionBuffer != null) { projectionBuffer.SourceBuffersChangedImmediate -= OnSourceBuffersChanged; } _sourceBuffer = null; } }
public IProjectionBuffer CreateProjectionBuffer(IProjectionEditResolver projectionEditResolver, IList <object> trackingSpans, ProjectionBufferOptions options) { // projectionEditResolver is allowed to be null. if (trackingSpans == null) { throw new ArgumentNullException(nameof(trackingSpans)); } IProjectionBuffer buffer = new ProjectionBuffer(this, projectionEditResolver, ProjectionContentType, trackingSpans, _differenceService, _textDifferencingSelectorService.DefaultTextDifferencingService, options, _guardedOperations); RaiseProjectionBufferCreatedEvent(buffer); return(buffer); }
public ProjectionSnapshotDoppelganger(ProjectionBuffer projectionBuffer, ITextVersion version, IList <SnapshotSpan> sourceSpans, ITextSnapshot doppelSnap) : base(projectionBuffer, version, sourceSpans) { this.doppelSnap = doppelSnap; }
public ProjectionSnapshot(ProjectionBuffer projectionBuffer, ITextVersion2 version, StringRebuilder content, IList <SnapshotSpan> sourceSpans) : base(version, content) { this.projectionBuffer = projectionBuffer; this.sourceSpans = new ReadOnlyCollection <SnapshotSpan>(sourceSpans); this.cumulativeLengths = new int[sourceSpans.Count + 1]; this.cumulativeLineBreakCounts = new int[sourceSpans.Count + 1]; this.sourceSnapshotMap = new Dictionary <ITextSnapshot, List <InvertedSource> >(); for (int s = 0; s < sourceSpans.Count; ++s) { SnapshotSpan sourceSpan = sourceSpans[s]; this.totalLength += sourceSpan.Length; this.cumulativeLengths[s + 1] = this.cumulativeLengths[s] + sourceSpan.Length; // Most source spans won't change when generating a new projection snapshot, // which means we should be able to reuse the line break count from the previous // projection snapshot. int lineBreakCount = sourceSpan.Snapshot.GetLineNumberFromPosition(sourceSpan.End) - sourceSpan.Snapshot.GetLineNumberFromPosition(sourceSpan.Start); // todo: incorrect when span ends with \r and following begins with \n this.totalLineCount += lineBreakCount; this.cumulativeLineBreakCounts[s + 1] = this.cumulativeLineBreakCounts[s] + lineBreakCount; ITextSnapshot snapshot = sourceSpan.Snapshot; List <InvertedSource> invertedSources; if (!this.sourceSnapshotMap.TryGetValue(snapshot, out invertedSources)) { invertedSources = new List <InvertedSource>(); this.sourceSnapshotMap.Add(snapshot, invertedSources); } invertedSources.Add(new InvertedSource(sourceSpan.Span, this.cumulativeLengths[s])); } // The SourceSnapshots property is heavily used, so calculate it once this.sourceSnapshots = new ReadOnlyCollection <ITextSnapshot>(new List <ITextSnapshot>(this.sourceSnapshotMap.Keys)); // sort the per-buffer source span lists by position in source snapshot foreach (var v in this.sourceSnapshotMap.Values) { // sort by starting position. Spans can't overlap, but we do need null spans at a particular position // to precede non-null spans at that position, so if starting positions are equal, compare the ends. v.Sort((left, right) => (left.sourceSpan.Start == right.sourceSpan.Start ? left.sourceSpan.End - right.sourceSpan.End : left.sourceSpan.Start - right.sourceSpan.Start)); } if (BufferGroup.Tracing) { Debug.WriteLine(LocalToString()); } if (this.totalLength != version.Length) { Debug.Fail(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Projection Snapshot Inconsistency. Sum of spans: {0}, Previous + delta: {1}", this.totalLength, version.Length)); throw new InvalidOperationException(Strings.InvalidLengthCalculation); } OverlapCheck(); }