/// <summary>
        /// Returns negative value if the point is less than the span start,
        /// positive if greater than or equal to the span end, and 0 otherwise.
        /// </summary>
        private static int CompareToSpan(ITextView textView, ReadOnlyCollection <SnapshotSpan> sourceSpans, int index, SnapshotPoint point)
        {
            // If this span is zero-width and there are multiple projections of the
            // containing snapshot in the projection buffer, MapUpToBuffer will return
            // multiple (ambiguous) projection spans. To avoid that, we compare the
            // point to the end point of the nearest non-zero width span instead.
            int indexToCompare = index;

            while (sourceSpans[indexToCompare].IsEmpty)
            {
                if (indexToCompare == 0)
                {
                    // Empty span at start of buffer. Point
                    // must be to the right of span.
                    return(1);
                }
                indexToCompare--;
            }

            var sourceSpan = sourceSpans[indexToCompare];

            Debug.Assert(sourceSpan.Length > 0);

            var mappedSpans = textView.BufferGraph.MapUpToBuffer(sourceSpan, SpanTrackingMode.EdgeInclusive, textView.TextBuffer);

            Debug.Assert(mappedSpans.Count == 1);

            var mappedSpan = mappedSpans[0];

            Debug.Assert(mappedSpan.Length == sourceSpan.Length);

            if (indexToCompare < index)
            {
                var result = point.CompareTo(mappedSpan.End);
                return((result == 0) ? 1 : result);
            }
            else
            {
                var result = point.CompareTo(mappedSpan.Start);
                if (result <= 0)
                {
                    return(result);
                }
                result = point.CompareTo(mappedSpan.End);
                return((result < 0) ? 0 : 1);
            }
        }
            /// <summary>
            /// Returns negative value if the point is less than the span start,
            /// positive if greater than or equal to the span end, and 0 otherwise.
            /// </summary>
            private static int CompareToSpan(ITextView textView, ReadOnlyCollection<SnapshotSpan> sourceSpans, int index, SnapshotPoint point)
            {
                // If this span is zero-width and there are multiple projections of the
                // containing snapshot in the projection buffer, MapUpToBuffer will return
                // multiple (ambiguous) projection spans. To avoid that, we compare the
                // point to the end point of the nearest non-zero width span instead.
                int indexToCompare = index;
                while (sourceSpans[indexToCompare].IsEmpty)
                {
                    if (indexToCompare == 0)
                    {
                        // Empty span at start of buffer. Point
                        // must be to the right of span.
                        return 1;
                    }
                    indexToCompare--;
                }

                var sourceSpan = sourceSpans[indexToCompare];
                Debug.Assert(sourceSpan.Length > 0);

                var mappedSpans = textView.BufferGraph.MapUpToBuffer(sourceSpan, SpanTrackingMode.EdgeInclusive, textView.TextBuffer);
                Debug.Assert(mappedSpans.Count == 1);

                var mappedSpan = mappedSpans[0];
                Debug.Assert(mappedSpan.Length == sourceSpan.Length);

                if (indexToCompare < index)
                {
                    var result = point.CompareTo(mappedSpan.End);
                    return (result == 0) ? 1 : result;
                }
                else
                {
                    var result = point.CompareTo(mappedSpan.Start);
                    if (result <= 0)
                    {
                        return result;
                    }
                    result = point.CompareTo(mappedSpan.End);
                    return (result < 0) ? 0 : 1;
                }
            }