how expand/move range object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas

    how expand/move range object

    Hi dudes,

    I have a range object for text (not the one in the IE, the one for
    Mozilla). Now I have a function to reduce/move the range in the text
    to the LEFT, e.g.:
    range.setStart( range.startCont ainer, startPos-1);
    range.setEnd(ra nge.endContaine r, endPos-1);
    range ist the range object created via
    window.getSelec tion.getRangeAt (0).
    Now I have the problem to extend or simply move the range to the
    RIGHT.
    range.setEnd(ra nge.endContaine r, endPos + 1);
    range.setStart( range.startCont ainer, startPos + 1);
    I thought I could simply switch the sign, but this doesn't work, I get
    the following error (yes, I exchanged the order for expanding, so that
    first the endContainer is moved and afterwards the startContainer ;-)
    ):

    Error: [Exception... "Index or size is negative or greater than the
    allowed amount" code: "1" nsresult: "0x80530001
    (NS_ERROR_DOM_I NDEX_SIZE_ERR)" location: "xxx.html Line: 79"]
    Source File: xxx.html
    Line: 79

    Thx for any help,
    Thomas
  • Martin Honnen

    #2
    Re: how expand/move range object



    Thomas wrote:
    [color=blue]
    > I have a range object for text (not the one in the IE, the one for
    > Mozilla). Now I have a function to reduce/move the range in the text
    > to the LEFT, e.g.:
    > range.setStart( range.startCont ainer, startPos-1);
    > range.setEnd(ra nge.endContaine r, endPos-1);
    > range ist the range object created via
    > window.getSelec tion.getRangeAt (0).
    > Now I have the problem to extend or simply move the range to the
    > RIGHT.
    > range.setEnd(ra nge.endContaine r, endPos + 1);
    > range.setStart( range.startCont ainer, startPos + 1);
    > I thought I could simply switch the sign, but this doesn't work, I get
    > the following error (yes, I exchanged the order for expanding, so that
    > first the endContainer is moved and afterwards the startContainer ;-)
    > ):
    >
    > Error: [Exception... "Index or size is negative or greater than the
    > allowed amount" code: "1" nsresult: "0x80530001
    > (NS_ERROR_DOM_I NDEX_SIZE_ERR)" location: "xxx.html Line: 79"]
    > Source File: xxx.html
    > Line: 79[/color]

    That will probably depend on what kind of node the current end or
    startContainer is and whether there is anything left to move to. If
    needed you must change the container.

    --

    Martin Honnen


    Comment

    Working...