示例#1
0
        private FrugalList <SnapshotSpan> MapUpOneLevel(FrugalList <SnapshotSpan> spans, ref ITextSnapshot chosenSnapshot, Predicate <ITextSnapshot> match, FrugalList <Span> topSpans)
        {
            FrugalList <SnapshotSpan> upSpans = new FrugalList <SnapshotSpan>();

            foreach (SnapshotSpan span in spans)
            {
                FrugalList <IProjectionBufferBase> targetBuffers;
                if (this.importingProjectionBufferMap.TryGetValue(span.Snapshot.TextBuffer, out targetBuffers))
                {
                    if (targetBuffers != null)  // make sure we don't fall off the top
                    {
                        foreach (IProjectionBufferBase projBuffer in targetBuffers)
                        {
                            IList <Span> projSpans = projBuffer.CurrentSnapshot.MapFromSourceSnapshot(span);
                            if (projBuffer.CurrentSnapshot == chosenSnapshot)
                            {
                                topSpans.AddRange(projSpans);
                            }
                            else if (chosenSnapshot == null && match(projBuffer.CurrentSnapshot))
                            {
                                chosenSnapshot = projBuffer.CurrentSnapshot;
                                topSpans.AddRange(projSpans);
                            }
                            else
                            {
                                foreach (Span projSpan in projSpans)
                                {
                                    upSpans.Add(new SnapshotSpan(projBuffer.CurrentSnapshot, projSpan));
                                }
                            }
                        }
                    }
                }
            }
            return(upSpans);
        }
        public IEnumerable <ITextBuffer> ResolveBuffersForCommand <TArgs>() where TArgs : EditorCommandArgs
        {
            var sourceSnapshotPoints = new FrugalList <SnapshotPoint>(new[] { _textView.Caret.Position.BufferPosition });
            var resolvedBuffers      = new FrugalList <ITextBuffer>();

            for (int i = 0; i < sourceSnapshotPoints.Count; i++)
            {
                SnapshotPoint curSnapshotPoint = sourceSnapshotPoints[i];
                if (curSnapshotPoint.Snapshot is IProjectionSnapshot curProjectionSnapshot)
                {
                    sourceSnapshotPoints.AddRange(curProjectionSnapshot.MapToSourceSnapshots(curSnapshotPoint));
                }

                // As the set of buffers isn't likely to exceed 5, just use the list to determine whether we've seen it before
                ITextBuffer curBuffer = curSnapshotPoint.Snapshot.TextBuffer;
                if (!resolvedBuffers.Contains(curBuffer))
                {
                    resolvedBuffers.Add(curBuffer);
                }
            }

            return(resolvedBuffers);
        }
        protected internal override NormalizedSpanCollection GetReadOnlyExtentsImplementation(Span span)
        {
            // TODO: make something other than dead slow

            FrugalList <Span> result = new FrugalList <Span>(base.GetReadOnlyExtentsImplementation(span));

            IList <SnapshotSpan> restrictionSpans = this.CurrentBaseSnapshot.MapToSourceSnapshotsForRead(span);

            foreach (SnapshotSpan restrictionSpan in restrictionSpans)
            {
                SnapshotSpan?overlapSpan = (restrictionSpan.Span == span) ? restrictionSpan : restrictionSpan.Overlap(span);
                if (overlapSpan.HasValue)
                {
                    BaseBuffer baseBuffer = (BaseBuffer)restrictionSpan.Snapshot.TextBuffer;
                    NormalizedSpanCollection sourceExtents = baseBuffer.GetReadOnlyExtents(overlapSpan.Value);
                    foreach (Span sourceExtent in sourceExtents)
                    {
                        result.AddRange(this.CurrentBaseSnapshot.MapFromSourceSnapshot(new SnapshotSpan(restrictionSpan.Snapshot, sourceExtent)));
                    }
                }
            }

            return(new NormalizedSpanCollection(result));
        }