views:

333

answers:

1

I have a script that (I think) needs to use surroundContents to wrap the selection area. Doing so allows me to append something, and then reassign the range as the selection.

I believe I've narrowed the problem down to a misuse of getRangeAt, but I'm not quite sure how to correct it.

Here's the brief bit of code:

     function getRangeObject(selectionObject) {
  // Moz
  if (selectionObject.getRangeAt) {
   return selectionObject.getRangeAt(0);
  }

And here's line 89 where it throws an error at me:

rangeObject.surroundContents(newNode);

And of course, here's the error:

Error: uncaught exception: [Exception... "The boundary-points of a range does not meet specific requirements." code: "1" nsresult: "0x805c0001 (NS_ERROR_DOM_RANGE_BAD_BOUNDARYPOINTS_ERR)" location: "http://www.latentmotion.com/insertNode/index26.html Line: 89"]

If it's helpful to see the whole thing, you can view the script (so far) here: http://www.latentmotion.com/insertNode/index26.html

And the text selection helper that I was going off of was quirksmode - which doesn't detail the use of multiple ranges, located here.

Thanks in advance for your help.

A: 

I think the error message describes the problem well. This section of the DOM Range spec describes what leads to an exception being thrown by a Range when using surroundContents.

Tim Down
Yeah - that might be it. I read the spec you linked to, but am still unsure of how to fix the problem. Is there some way of cleaning up / completely selecting the non-text node that throws the error?Maybe I could detect the partially selected node and somehow close it out?
Matrym
It might help if you said more precisely what you're trying to do. What do you want to append and where?
Tim Down