Re: [editing] Avoiding selections with no corresponding range, to simplify authoring

On 1/11/12 11:41 AM, Aryeh Gregor wrote:
> Also, while I'm at it, how about collapsing at
> (document.documentElement, 0) instead of (document, 0)?

Then you have to handle the case when document.documentElement is null.

And yes, this has come up before; there are scripts out there that 
remove documentElements, do some stuff, insert new documentElements, etc.

> This has the minor added benefit of avoiding Selection boundary points that aren't
> in an Element or Text node

This would happen anyway if you set up a selection inside 
document.documentElement and someone removes the documentElement; the 
normal range algorithm will give you endpoints inside the Document.  so 
you really can't enforce this condition.

-Boris

Received on Wednesday, 11 January 2012 17:37:14 UTC