Esempio n. 1
0
def findTextPoint(node, offset):
    """
    If the found range is not on a text node, this finds the cooresponding
    text node to where the selection is.  If it is on a text node, just
    directly creates the endpoint from it.

    @param node node returned as an endpoint of a range
    @param offset offset returned to the endpoint of a range
    @return A range end point with a proper (or None) text node
    """
    if DOM.getNodeType(node) == DOM.TEXT_NODE:
        res = RangeEndPoint(node, offset)
    else:
        # search backwards unless this is after the last node
        dirn = offset >= DOM.getChildCount(node)
        child = (DOM.getChildCount(node) == 0) and node or \
            DOM.getChild(node, dirn and (offset - 1) or offset)
        # Get the previous/next text node
        text = RangeUtil.getAdjacentTextElement(child, dirn)
        if text is None:
            # If we didn't find a text node in the preferred direction,
            # try the other direction
            dirn = not dirn
            text = RangeUtil.getAdjacentTextElement(child, dirn)

        res = RangeEndPoint(text, dirn)

    return res
Esempio n. 2
0
    def setRange(self, arg1, arg2=None):
        """
        Sets the range to encompass the given element.  May not work around
        non-text containing elements.

        @param element Element to surround by this range
        @return whether a range can be placed around this element.

        Set the range to be between the two given points.  Both points must be
        within the same document, and end must come after start.

        @param startPoint Start point to set the range to
        @param endPoint End point to set the range to
        """
        if arg2 is None:
            firstText = RangeUtil.getAdjacentTextElement(arg1, arg1, True, False)
            lastText = RangeUtil.getAdjacentTextElement(arg1, arg1, False, False)

            if (firstText is None) or (lastText is None):
                return False

            startPoint = RangeEndPoint(firstText, 0)
            endPoint = RangeEndPoint(lastText, lastText.length)

        else:
            startPoint = arg1
            endPoint = arg2

        assert startPoint.getNode().ownerDocument == endPoint.getNode().ownerDocument

        self._setRange(startPoint, endPoint)
        self.m_range = None
Esempio n. 3
0
def findTextPoint(node, offset):
    if DOM.getNodeType(node) == DOM.TEXT_NODE:
        res = RangeEndPoint(node, offset)
    else:
        # search backwards unless this is after the last node
        dirn = offset >= DOM.getChildCount(node)
        child = (DOM.getChildCount(node) == 0) and node or \
            DOM.getChild(node, dirn and (offset - 1) or offset)
        # Get the previous/next text node
        text = RangeUtil.getAdjacentTextElement(child, dirn)
        if text is None:
            # If we didn't find a text node in the preferred direction,
            # try the other direction
            dirn = not dirn
            text = RangeUtil.getAdjacentTextElement(child, dirn)

        res = RangeEndPoint(text, dirn)

    return res
Esempio n. 4
0
    def setRange(self, arg1, arg2=None):
        if arg2 is None:
            firstText = RangeUtil.getAdjacentTextElement(arg1, arg1, True, False)
            lastText = RangeUtil.getAdjacentTextElement(arg1, arg1, False, False)

            if (firstText is None) or (lastText is None):
                return False

            startPoint = RangeEndPoint(firstText, 0)
            endPoint = RangeEndPoint(lastText, lastText.length)

        else:
            startPoint = arg1
            endPoint = arg2

        assert startPoint.getNode().ownerDocument == endPoint.getNode().ownerDocument

        self._setRange(startPoint, endPoint)
        self.m_range = None
Esempio n. 5
0
    def setRange(self, arg1, arg2=None):
        """
        Sets the range to encompass the given element.  May not work around
        non-text containing elements.

        @param element Element to surround by this range
        @return whether a range can be placed around this element.

        Set the range to be between the two given points.  Both points must be
        within the same document, and end must come after start.

        @param startPoint Start point to set the range to
        @param endPoint End point to set the range to
        """
        if arg2 is None:
            firstText = RangeUtil.getAdjacentTextElement(
                arg1, arg1, True, False)
            lastText = RangeUtil.getAdjacentTextElement(
                arg1, arg1, False, False)

            if (firstText is None) or (lastText is None):
                return False

            startPoint = RangeEndPoint(firstText, 0)
            endPoint = RangeEndPoint(lastText, lastText.length)

        else:
            startPoint = arg1
            endPoint = arg2

        assert (startPoint.getNode().ownerDocument ==
                endPoint.getNode().ownerDocument)

        self._setRange(startPoint, endPoint)
        self.m_range = None
Esempio n. 6
0
    def setRange(self, arg1, arg2=None):
        if arg2 is None:
            firstText = RangeUtil.getAdjacentTextElement(arg1, arg1, True, False)
            lastText = RangeUtil.getAdjacentTextElement(arg1, arg1, False, False)

            if (firstText is None)  or  (lastText is None):
                return False

            startPoint = RangeEndPoint(firstText, 0)
            endPoint = RangeEndPoint(lastText, lastText.length)

        else:
            startPoint = arg1
            endPoint = arg2

        assert (startPoint.getNode().ownerDocument ==
                    endPoint.getNode().ownerDocument)

        self._setRange(startPoint, endPoint)
        self.m_range = None
Esempio n. 7
0
 def setupLastEndpoints(self):
     self.m_lastStartPoint = RangeEndPoint(self.m_startPoint)
     self.m_lastEndPoint = RangeEndPoint(self.m_endPoint)