W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2000

range boundary point update after insertion

From: <tng@ca.ibm.com>
Date: Fri, 1 Dec 2000 12:22:43 -0500
To: www-dom@w3.org
Message-ID: <OFA06D318C.6DD5714A-ON852569A8.00558B4B@torolab.ibm.com>
Hi,

I have a question regarding the range boundary point update after
insertion:

Consider the following case:

<root>hello</root>

Scenario 1:
   rangeA is set as:

     start container: hello
     start offset: 1
     end container: hello
     end offset: 5

   Then after inserting the node <foo/> (rangeA.insertNode(foo);), the
   document has:

   <root>h<foo/>ello</root>

   And rangeA is updated as:

     start container: h
     start offset: 1
     end container: ello
     end offset: 4

   which is correct.

Scenario 2:
   What about if rangeA was instead set as

     start container: hello
     start offset: 1
     end container: root
     end offset: 1

   which in fact covers the same range of text as in the first scenario.
   But after rangeA.insertNode(foo):

   <root>h<foo/>ello</root>

   Should rangeA become:

     start container: h
     start offset: 1
     end container: root
     end offset: 3

   or

     start container: h
     start offset: 1
     end container: root
     end offset: 1

   ??

According to the spec, it says:

   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.

So sounds like the latter one (end offset remains not changed) should
happen for scenario 2 since the end boundary-point and the insertion point
did not have same container ...

Thus rangeA becomes covering nothing after insertion in scenario 2; while
in the first scenario, rangeA is updated and covers "</foo>ello" after
insertion.

Is this correct?  Does it make sense?

Thanks!

Regards,

Tinny Ng
XML Parsers Development
IBM Toronto Laboratory, email: tng@ca.ibm.com
Received on Friday, 1 December 2000 12:23:13 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:48 GMT