Пример #1
0
        public RtRange SplitRange(RtRange range)
        {
            // todo: bug: need +1 on the end?
            var firstGlobalIndex = GetGlobalIndex(range.FirstCharPos);
            var lastGlobalIndex  = GetGlobalIndex(range.LastCharPos);

            SplitSpan(GetPositionForCharIndex(firstGlobalIndex, RichTextPositionPreference.NextSpan), out _);
            SplitSpan(GetPositionForCharIndex(lastGlobalIndex, RichTextPositionPreference.PreviousSpan), out _);

            return(new RtRange(
                       GetPositionForCharIndex(firstGlobalIndex, RichTextPositionPreference.NextSpan),
                       GetPositionForCharIndex(lastGlobalIndex, RichTextPositionPreference.PreviousSpan)));
        }
Пример #2
0
        public bool TryGetCommonParagraphProperty <T>(RtRange range, Func <IRtParagraph, T> getProp, out T common)
            where T : IEquatable <T>
        {
            var firstPara = Paragraphs[range.FirstCharPos.ParaIndex];

            common = getProp(firstPara);
            foreach (var para in Paragraphs.Skip(range.FirstCharPos.ParaIndex + 1).Take(range.LastCharPos.ParaIndex - range.FirstCharPos.ParaIndex))
            {
                var other = getProp(para);
                if (!common.Equals(other))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
        public bool TryGetCommonSpanProperty <T>(RtRange range, Func <IRtSpan, T> getProp, out T common)
            where T : IEquatable <T>
        {
            var spans     = EnumerateSpans(range);
            var firstSpan = spans.First();

            common = getProp(firstSpan);
            foreach (var span in spans.Skip(1))
            {
                var other = getProp(span);
                if (!common.Equals(other))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #4
0
        public IEnumerable <IRtSpan> EnumerateSpans(RtRange range)
        {
            var firstPara = Paragraphs[range.FirstCharPos.ParaIndex];
            var firstSpan = firstPara.Spans[range.FirstCharPos.SpanIndex];

            var lastPara = Paragraphs[range.LastCharPos.ParaIndex];
            var lastSpan = lastPara.Spans[range.LastCharPos.SpanIndex];

            if (firstSpan == lastSpan)
            {
                yield return(firstSpan);
            }
            else if (firstPara == lastPara)
            {
                for (int i = range.FirstCharPos.SpanIndex; i <= range.LastCharPos.SpanIndex; i++)
                {
                    yield return(firstPara.Spans[i]);
                }
            }
            else
            {
                for (int i = range.FirstCharPos.SpanIndex; i < firstPara.Spans.Count; i++)
                {
                    yield return(firstPara.Spans[i]);
                }
                for (int i = range.FirstCharPos.ParaIndex + 1; i < range.LastCharPos.ParaIndex; i++)
                {
                    foreach (var span in Paragraphs[i].Spans)
                    {
                        yield return(span);
                    }
                }
                for (int i = 0; i <= range.LastCharPos.SpanIndex; i++)
                {
                    yield return(lastPara.Spans[i]);
                }
            }
        }