Esempio n. 1
0
        /// <summary>
        /// Given a point in the template buffer gets the text for that template tag.
        /// </summary>
        internal string GetTemplateText(SnapshotPoint point, out TemplateTokenKind kind, out int start)
        {
            Debug.Assert(point.Snapshot.TextBuffer == _templateBuffer);

            var realPoint = _bufferGraph.MapDownToBuffer(
                point,
                PointTrackingMode.Positive,
                _diskBuffer,
                PositionAffinity.Successor);

            if (realPoint != null)
            {
                // TODO: Binary search would be better
                var pointVal = realPoint.Value;
                for (int i = 0; i < _spans.Count; i++)
                {
                    var startPoint = _spans[i].DiskBufferSpan.GetSpan(_diskBuffer.CurrentSnapshot);
                    if (startPoint.Start <= pointVal.Position && startPoint.End >= pointVal.Position)
                    {
                        kind  = _spans[i].Kind;
                        start = startPoint.Start;
                        return(_spans[i].DiskBufferSpan.GetText(_diskBuffer.CurrentSnapshot));
                    }
                }
            }
            kind  = TemplateTokenKind.None;
            start = 0;
            return(null);
        }
        public static SnapshotSpan?MapUpOrDownToBuffer(this IBufferGraph bufferGraph, SnapshotSpan span, ITextBuffer targetBuffer)
        {
            var direction = ClassifyBufferMapDirection(span.Snapshot.TextBuffer, targetBuffer);

            switch (direction)
            {
            case BufferMapDirection.Identity:
                return(span);

            case BufferMapDirection.Down:
            {
                var spans = bufferGraph.MapDownToBuffer(span, SpanTrackingMode.EdgeExclusive, targetBuffer);
                return(spans.Select(s => (SnapshotSpan?)s).FirstOrDefault());
            }

            case BufferMapDirection.Up:
            {
                var spans = bufferGraph.MapUpToBuffer(span, SpanTrackingMode.EdgeExclusive, targetBuffer);
                return(spans.Select(s => (SnapshotSpan?)s).FirstOrDefault());
            }

            default:
                return(null);
            }
        }
Esempio n. 3
0
        public static SnapshotPoint?MapUpOrDownToBuffer(this IBufferGraph bufferGraph, SnapshotPoint point, ITextBuffer targetBuffer)
        {
            var direction = ClassifyBufferMapDirection(point.Snapshot.TextBuffer, targetBuffer);

            switch (direction)
            {
            case BufferMapDirection.Identity:
                return(point);

            case BufferMapDirection.Down:
            {
                return(bufferGraph.MapDownToBuffer(point, PointTrackingMode.Positive, targetBuffer, PositionAffinity.Predecessor));
            }

            case BufferMapDirection.Up:
            {
                return(bufferGraph.MapUpToBuffer(point, PointTrackingMode.Positive, PositionAffinity.Predecessor, targetBuffer));
            }

            default:
                return(null);
            }
        }