Ejemplo n.º 1
0
        } // End GetTextBetweenPointers.
        // </Snippet_TextPointer_GetTextInRun>

        // <Snippet_TextPointer_IsInSameDocument>
        // This method first checks for compatible text container scope, and then checks whether
        // a specified position is between two other specified positions.
        bool IsPositionContainedBetween(TextPointer positionToTest, TextPointer start, TextPointer end)
        {
            // Note that without this check, an exception will be raised by CompareTo if positionToTest 
            // does not point to a position that is in the same text container used by start and end.
            //
            // This test also implicitely indicates whether start and end share a common text container.
            if (!positionToTest.IsInSameDocument(start) || !positionToTest.IsInSameDocument(end)) 
                return false;
            
            return start.CompareTo(positionToTest) <= 0 && positionToTest.CompareTo(end) <= 0;
        }
Ejemplo n.º 2
0
        public int GetIndex(TextPointer tp, LogicalDirection dir)
        {
            Debug.Assert(tp.IsInSameDocument(Doc.ContentStart));

            tp = tp.GetInsertionPosition(dir);

            if (tp.Parent is FlowDocument)
            {
                return(0);
            }

            TextElement parent = (TextElement)tp.Parent;

            int index = FindStartIndex(parent);

            if (index < 0)
            {
                return(-1);
            }

            if (parent is Run)
            {
                return(index + parent.ContentStart.GetOffsetToPosition(tp));
            }
            else
            {
                return(index);
            }
        }