コード例 #1
0
        public bool Contains(MarkupRange testRange)
        {
            // Select just the inner-most text to normalize the MarkupRange before comparing it.
            testRange.SelectInner();

            int pos = BinarySearch(words.Keys, testRange.Start.PointerRaw, new MarkupPointerComparer());

            if (pos >= 0)
            {
                if (words.Values[pos].End.IsLeftOf(testRange.End))
                {
                    Debug.Fail("testRange partially overlaps with range");
                    try
                    {
                        Debug.WriteLine("testRange: [" + testRange.Text + "]");
                        Debug.WriteLine("thisRange: [" + words.Values[pos].Text + "]");
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.ToString());
                    }
                }
                return(true);
            }

            pos = (~pos) - 1;

            if (pos < 0)
            {
                return(false);
            }

            if (words.Values[pos].End.IsRightOf(testRange.Start))
            {
                if (words.Values[pos].End.IsLeftOf(testRange.End))
                {
#if DEBUG
                    MarkupRange temp = testRange.Clone();
                    temp.Start.MoveToPointer(words.Values[pos].End);
                    if ((temp.Text ?? "").Trim().Length > 0)
                    {
                        Debug.Fail("testRange partially overlaps with range");
                        try
                        {
                            Debug.WriteLine("testRange: [" + testRange.Text + "]");
                            Debug.WriteLine("thisRange: [" + words.Values[pos].Text + "]");
                            Debug.WriteLine("overlap:   [" + temp.Text + "]");
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.ToString());
                        }
                    }
#endif
                }
                return(true);
            }

            return(false);
        }
コード例 #2
0
        public void Add(MarkupRange range)
        {
            MarkupRange newRange = range.Clone();

            newRange.Start.Cling   = false;
            newRange.End.Cling     = false;
            newRange.Start.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Right;
            newRange.End.Gravity   = _POINTER_GRAVITY.POINTER_GRAVITY_Left;

            // Select just the inner-most text so that it is easier to compare to other MarkupRanges.
            newRange.SelectInner();

            try
            {
                words.Add(newRange.Start.PointerRaw, newRange);
            }
            catch (ArgumentException ex)
            {
                Trace.Fail(ex.ToString());
            }
        }