Re: range boundary point update after insertion

> followed by rangeA.insertNode(foo),  I would expect
>
>   <root>h<foo/>ello</root>
>
>   Range:
>     start container: h
>     start offset: 1
>     end container: root
>     end offset: 3

My logicial sense also thinks this way.  But reading the spec (DOM Level 2
Traversal and Range Specification):

   [2.12.1]
   The only case in which the boundary-point will be changed after the
   insertion is when the boundary-point and the insertion point have the
   same container [p.32] and the offset [p.32] of the insertion point is
   strictly less than the offset [p.32] of the Range's boundary-point.

the condition "same container" quite confuses me, and a clarification is
recommended.

Similarly here is another confusing boundary update scenario, say the
document has:
   <root>
      hello
   </root>

and rangeB is set as:
   start container: root
   start offset: 0
   end container: root
   end offset: 1

now we do a document mutation, and split the Text Node:
   hello.splitText(1);

so the document becomes
   <root>
     h
     ello
   </root>

How is the rangeB being modified after this document mutation?

Will it be:
   start container: root
   start offset: 0
   end container: root
   end offset: 2
or
   start container: root
   start offset: 0
   end container: root
   end offset: 1
??

The spec says:

   [2.12.1]
   Note that when content is inserted at a boundary-point, it is ambiguous
   as to where the boundary-point should be repositioned if its relative
   position is to be maintained. There are two possibilities: at the start
   or at the end of the newly inserted content. We have chosen that in this
   case neither the container [p.32] nor offset [p.32] of the
   boundary-point is changed. As a result, the boundary-point will be
   positioned at the start of the newly inserted content.

And the new text node "ello" is indeed a insertion at rangeB's end boundary
point.  And according to the spec above, the boundary-pint will be
positioned at the start of the newly inserted content.  Thus sounds like
the latter one (i.e. end container: root, end offset: 1) should happen.
But again similar to previous example, my logical sense thinks the first
one make more sense.....

May be I've missed something .....  Any help in clarification appreciated.

Thanks!

Tinny

Received on Friday, 1 December 2000 15:55:00 UTC