Use DOM4's range set algorithm
authorAryeh Gregor <ayg@aryeh.name>
Thu, 12 Jan 2012 10:10:06 -0700
changeset 6870ef300a5c14f
parent 686 56c83bbaa44c
child 688 abb6e4cc12ec
Use DOM4's range set algorithm

This makes the extend test correct -- it previously didn't match the
spec.

Fixes: https://www.w3.org/Bugs/Public/show_bug.cgi?id=15533
Reported-By: Stig Halvorsen
editing.html
preprocess
source.html
     1.1 --- a/editing.html	Thu Jan 12 09:18:37 2012 -0700
     1.2 +++ b/editing.html	Thu Jan 12 10:10:06 2012 -0700
     1.3 @@ -860,6 +860,8 @@
     1.4  part of the selection's document?  Assuming it works, how is it presented to
     1.5  the user?
     1.6  
     1.7 +<p class=XXX>What does <code title="">getSelection().getRangeAt(0).detach()</code> do?
     1.8 +
     1.9  <dl class=domintro>
    1.10    <dt><var title="">selection</var> . <code title=dom-Selection-anchorNode><a href=#dom-selection-anchornode>anchorNode</a></code>
    1.11    <dd>
    1.12 @@ -961,17 +963,10 @@
    1.13  are the same (including if both are null).  Otherwise it must return false.
    1.14  
    1.15  <p>The <dfn id=dom-selection-collapse title=dom-Selection-collapse><code>collapse(<var title="">parentNode</var>,
    1.16 -<var title="">offset</var>)</code></dfn> method must run the following steps:
    1.17 -
    1.18 -<ol>
    1.19 -  <li>If <var title="">offset</var> is greater than the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node-length title=concept-node-length>length</a> of
    1.20 -  <var title="">parentNode</var>, <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-throw title=concept-throw>throw</a> an <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#indexsizeerror>IndexSizeError</a></code> exception and abort
    1.21 -  these steps.
    1.22 -
    1.23 -  <li>Set the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> to a new <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> object with
    1.24 -  <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a> and <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a> both equal to (<var title="">parentNode</var>,
    1.25 -  <var title="">offset</var>).
    1.26 -</ol>
    1.27 +<var title="">offset</var>)</code></dfn> method must create a new <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a>,
    1.28 +<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-bp-set title=concept-range-bp-set>set</a> both its <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a> and <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a> to
    1.29 +(<var title="">parentNode</var>, <var title="">offset</var>), and set the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s
    1.30 +<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> to the newly-created <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a>.
    1.31  
    1.32  <p class=comments>For collapseToStart/End, IE9 mutates the existing range,
    1.33  while Firefox 9.0a2 and Chrome 15 dev replace it with a new one.  The spec
    1.34 @@ -980,15 +975,17 @@
    1.35  
    1.36  <p>The <dfn id=dom-selection-collapsetostart title=dom-Selection-collapseToStart><code>collapseToStart()</code></dfn> method
    1.37  must <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-throw title=concept-throw>throw</a> an <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror>InvalidStateError</a></code> exception if the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s
    1.38 -<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> is null.  Otherwise, it must set the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> to
    1.39 -a new <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> object with <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a> and <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a> both equal to the
    1.40 -<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s old <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a>.
    1.41 +<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> is null.  Otherwise, it must create a new <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> object,
    1.42 +<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-bp-set title=concept-range-bp-set>set</a> both its <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a> and <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a> to the
    1.43 +<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a>, and then set the
    1.44 +<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> to the newly-created <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a>.
    1.45  
    1.46  <p>The <dfn id=dom-selection-collapsetoend title=dom-Selection-collapseToEnd><code>collapseToEnd()</code></dfn> method
    1.47  must <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-throw title=concept-throw>throw</a> an <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror>InvalidStateError</a></code> exception if the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s
    1.48 -<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> is null.  Otherwise, it must set the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> to
    1.49 -a new <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> object with <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a> and <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a> both equal to the
    1.50 -<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s old <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a>.
    1.51 +<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> is null.  Otherwise, it must create a new <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> object,
    1.52 +<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-bp-set title=concept-range-bp-set>set</a> both its <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a> and <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a> to the
    1.53 +<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a>, and then set the
    1.54 +<a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> to the newly-created <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a>.
    1.55  
    1.56  <p class=comments>Reverse-engineered circa January 2011.  IE doesn't support it, so I'm
    1.57  relying on Firefox (implemented extend() sometime before 2000) and WebKit
    1.58 @@ -998,6 +995,8 @@
    1.59  <p>The <dfn id=dom-selection-extend title=dom-Selection-extend><code>extend(<var title="">parentNode</var>,
    1.60  <var title="">offset</var>)</code></dfn> method must run these steps:
    1.61  
    1.62 +<p class=XXX>Does this mutate the existing range or make a new one?
    1.63 +
    1.64  <ol>
    1.65    <li>
    1.66    <p class=comments>Gecko raises a nonstandard exception, WebKit initializes to
    1.67 @@ -1007,12 +1006,6 @@
    1.68    <p>If the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> is null, <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-throw title=concept-throw>throw</a> an
    1.69    <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror>InvalidStateError</a></code> exception and abort these steps.
    1.70  
    1.71 -  <li>
    1.72 -  <p class=comments>Gecko and WebKit agree on this, Opera ignores the call.
    1.73 -
    1.74 -  <p>If <var title="">offset</var> is greater than <var title="">parentNode</var>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node-length title=concept-node-length>length</a>,
    1.75 -  <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-throw title=concept-throw>throw</a> an <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#indexsizeerror>IndexSizeError</a></code> exception and abort these steps.
    1.76 -
    1.77    <li>Let <var title="">range</var> be the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a>.
    1.78  
    1.79    <li>
    1.80 @@ -1022,9 +1015,9 @@
    1.81    case.)
    1.82  
    1.83    <p>If <var title="">parentNode</var>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-root title=concept-tree-root>root</a> is not the same as <var title="">range</var>'s
    1.84 -  <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-root title=concept-range-root>root</a>, set <var title="">range</var>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a> and <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a> to
    1.85 -  (<var title="">parentNode</var>, <var title="">offset</var>), set the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s
    1.86 -  <a href=#concept-selection-dir title=concept-selection-dir>direction</a> to backwards, and abort these steps.
    1.87 +  <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-root title=concept-range-root>root</a>, <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-bp-set title=concept-range-bp-set>set</a> <var title="">range</var>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a> and
    1.88 +  <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a> to (<var title="">parentNode</var>, <var title="">offset</var>), set the
    1.89 +  <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a href=#concept-selection-dir title=concept-selection-dir>direction</a> to backwards, and abort these steps.
    1.90  
    1.91    <li>Let <var title="">anchor</var> and <var title="">focus</var> be the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s
    1.92    <a href=#anchor>anchor</a> and <a href=#focus>focus</a>, and let <var title="">newFocus</var> be
    1.93 @@ -1040,9 +1033,9 @@
    1.94    <p>If <var title="">focus</var> and <var title="">newFocus</var> are the same, abort these
    1.95    steps.
    1.96  
    1.97 -  <li>Set <var title="">range</var>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a> to <var title="">anchor</var> and its
    1.98 -  <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a> to <var title="">newFocus</var>, if <var title="">anchor</var> is <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-bp-before title=concept-range-bp-before>before</a> or
    1.99 -  equal to <var title="">newFocus</var>; or vice versa, if it's <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-bp-after title=concept-range-bp-after>after</a>.
   1.100 +  <li><a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-bp-set title=concept-range-bp-set>Set</a> <var title="">range</var>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a> to <var title="">anchor</var> and
   1.101 +  its <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a> to <var title="">newFocus</var>, if <var title="">anchor</var> is <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-bp-before title=concept-range-bp-before>before</a>
   1.102 +  or equal to <var title="">newFocus</var>; or vice versa, if it's <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-bp-after title=concept-range-bp-after>after</a>.
   1.103  
   1.104    <li>If <var title="">newFocus</var> is <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-bp-before title=concept-range-bp-before>before</a> <var title="">anchor</var>, set the
   1.105    <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a href=#concept-selection-dir title=concept-selection-dir>direction</a> to backwards.  Otherwise, set it to forwards.
   1.106 @@ -1165,13 +1158,21 @@
   1.107  Opera 11.50 just does nothing in all my tests, as usual.
   1.108  </div>
   1.109  
   1.110 -<p>The <dfn id=dom-selection-selectallchildren title=dom-Selection-selectAllChildren><code>selectAllChildren(<var title="">parentNode</var>)</code></dfn>
   1.111 -method must <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-throw title=concept-throw>throw</a> an <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidnodetypeerror>InvalidNodeTypeError</a></code> if <var title="">parentNode</var> is a
   1.112 -<code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#documenttype>DocumentType</a></code>.  Otherwise, it must set the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> to
   1.113 -a new <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> whose <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start-node title=concept-range-start-node>start node</a> and <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end-node title=concept-range-end-node>end node</a> are <var title="">parentNode</var>,
   1.114 -whose <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start-offset title=concept-range-start-offset>start offset</a> is 0, and whose <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end-offset title=concept-range-end-offset>end offset</a> is the number of
   1.115 -<var title="">parentNode</var>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>children</a>; then set the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s
   1.116 -<a href=#concept-selection-dir title=concept-selection-dir>direction</a> to forwards.
   1.117 +<p>The <dfn id=dom-selection-selectallchildren title=dom-Selection-selectAllChildren><code>selectAllChildren(<var title="">node</var>)</code></dfn>
   1.118 +method must run the following steps:
   1.119 +
   1.120 +<ol>
   1.121 +  <li>Let <var title="">range</var> be a new <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a>.
   1.122 +
   1.123 +  <li><a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-bp-set title=concept-range-bp-set>Set</a> <var title="">range</var>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-start title=concept-range-start>start</a> to (<var title="">node</var>, 0).
   1.124 +
   1.125 +  <li><a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-bp-set title=concept-range-bp-set>Set</a> <var title="">range</var>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a> to (<var title="">node</var>, number
   1.126 +  of <var title="">node</var>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>children</a>).
   1.127 +
   1.128 +  <li>Set the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> to <var title="">range</var>.
   1.129 +
   1.130 +  <li>Set the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a href=#concept-selection-dir title=concept-selection-dir>direction</a> to <i title="">forwards</i>.
   1.131 +</ol>
   1.132  
   1.133  <p>The <dfn id=dom-selection-deletefromdocument title=dom-Selection-deleteFromDocument><code>deleteFromDocument()</code></dfn>
   1.134  method must do nothing if the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> is null, and
     2.1 --- a/preprocess	Thu Jan 12 09:18:37 2012 -0700
     2.2 +++ b/preprocess	Thu Jan 12 10:10:06 2012 -0700
     2.3 @@ -90,6 +90,7 @@
     2.4      'rangeend': '<span data-anolis-spec=dom title=concept-range-end>end</span>',
     2.5      'rangemutationrules': '<span data-anolis-spec=dom>range mutation rules</span>',
     2.6      'rangeroot': '<span data-anolis-spec=dom title=concept-range-root>root</span>',
     2.7 +    'rangeset': '<span data-anolis-spec=dom title=concept-range-bp-set>set</span>',
     2.8      'rangestart': '<span data-anolis-spec=dom title=concept-range-start>start</span>',
     2.9      'remove': '<span data-anolis-spec=dom title=concept-node-remove>remove</span>',
    2.10      'removeallranges': '<code title=dom-Selection-removeAllRanges>removeAllRanges()</code>',
     3.1 --- a/source.html	Thu Jan 12 09:18:37 2012 -0700
     3.2 +++ b/source.html	Thu Jan 12 10:10:06 2012 -0700
     3.3 @@ -806,6 +806,8 @@
     3.4  part of the selection's document?  Assuming it works, how is it presented to
     3.5  the user?
     3.6  
     3.7 +<p class=XXX>What does {{code|getSelection().getRangeAt(0).detach()}} do?
     3.8 +
     3.9  <dl class=domintro>
    3.10    <dt><var>selection</var> . <code title=dom-Selection-anchorNode>anchorNode</code>
    3.11    <dd>
    3.12 @@ -907,17 +909,10 @@
    3.13  are the same (including if both are null).  Otherwise it must return false.
    3.14  
    3.15  <p>The <dfn title=dom-Selection-collapse><code>collapse(<var>parentNode</var>,
    3.16 -<var>offset</var>)</code></dfn> method must run the following steps:
    3.17 -
    3.18 -<ol>
    3.19 -  <li>If <var>offset</var> is greater than the [[length]] of
    3.20 -  <var>parentNode</var>, [[throw]] an [[IndexSizeError]] exception and abort
    3.21 -  these steps.
    3.22 -
    3.23 -  <li>Set the [[contextobject]]'s [[range]] to a new [[range]] object with
    3.24 -  [[rangestart]] and [[rangeend]] both equal to (<var>parentNode</var>,
    3.25 -  <var>offset</var>).
    3.26 -</ol>
    3.27 +<var>offset</var>)</code></dfn> method must create a new [[range]],
    3.28 +[[rangeset]] both its [[rangestart]] and [[rangeend]] to
    3.29 +(<var>parentNode</var>, <var>offset</var>), and set the [[contextobject]]'s
    3.30 +[[range]] to the newly-created [[range]].
    3.31  
    3.32  <p class=comments>For collapseToStart/End, IE9 mutates the existing range,
    3.33  while Firefox 9.0a2 and Chrome 15 dev replace it with a new one.  The spec
    3.34 @@ -927,16 +922,18 @@
    3.35  <p>The <dfn
    3.36  title=dom-Selection-collapseToStart><code>collapseToStart()</code></dfn> method
    3.37  must [[throw]] an [[InvalidStateError]] exception if the [[contextobject]]'s
    3.38 -[[range]] is null.  Otherwise, it must set the [[contextobject]]'s [[range]] to
    3.39 -a new [[range]] object with [[rangestart]] and [[rangeend]] both equal to the
    3.40 -[[contextobject]]'s old [[range]]'s [[rangestart]].
    3.41 +[[range]] is null.  Otherwise, it must create a new [[range]] object,
    3.42 +[[rangeset]] both its [[rangestart]] and [[rangeend]] to the
    3.43 +[[contextobject]]'s [[range]]'s [[rangestart]], and then set the
    3.44 +[[contextobject]]'s [[range]] to the newly-created [[range]].
    3.45  
    3.46  <p>The <dfn
    3.47  title=dom-Selection-collapseToEnd><code>collapseToEnd()</code></dfn> method
    3.48  must [[throw]] an [[InvalidStateError]] exception if the [[contextobject]]'s
    3.49 -[[range]] is null.  Otherwise, it must set the [[contextobject]]'s [[range]] to
    3.50 -a new [[range]] object with [[rangestart]] and [[rangeend]] both equal to the
    3.51 -[[contextobject]]'s old [[range]]'s [[rangeend]].
    3.52 +[[range]] is null.  Otherwise, it must create a new [[range]] object,
    3.53 +[[rangeset]] both its [[rangestart]] and [[rangeend]] to the
    3.54 +[[contextobject]]'s [[range]]'s [[rangeend]], and then set the
    3.55 +[[contextobject]]'s [[range]] to the newly-created [[range]].
    3.56  
    3.57  <p class=comments>Reverse-engineered circa January 2011.  IE doesn't support it, so I'm
    3.58  relying on Firefox (implemented extend() sometime before 2000) and WebKit
    3.59 @@ -946,6 +943,8 @@
    3.60  <p>The <dfn title=dom-Selection-extend><code>extend(<var>parentNode</var>,
    3.61  <var>offset</var>)</code></dfn> method must run these steps:
    3.62  
    3.63 +<p class=XXX>Does this mutate the existing range or make a new one?
    3.64 +
    3.65  <ol>
    3.66    <li>
    3.67    <p class=comments>Gecko raises a nonstandard exception, WebKit initializes to
    3.68 @@ -955,12 +954,6 @@
    3.69    <p>If the [[contextobject]]'s [[range]] is null, [[throw]] an
    3.70    [[InvalidStateError]] exception and abort these steps.
    3.71  
    3.72 -  <li>
    3.73 -  <p class=comments>Gecko and WebKit agree on this, Opera ignores the call.
    3.74 -
    3.75 -  <p>If <var>offset</var> is greater than <var>parentNode</var>'s [[length]],
    3.76 -  [[throw]] an [[IndexSizeError]] exception and abort these steps.
    3.77 -
    3.78    <li>Let <var>range</var> be the [[contextobject]]'s [[range]].
    3.79  
    3.80    <li>
    3.81 @@ -970,9 +963,9 @@
    3.82    case.)
    3.83  
    3.84    <p>If <var>parentNode</var>'s [[root]] is not the same as <var>range</var>'s
    3.85 -  [[rangeroot]], set <var>range</var>'s [[rangestart]] and [[rangeend]] to
    3.86 -  (<var>parentNode</var>, <var>offset</var>), set the [[contextobject]]'s
    3.87 -  [[seldir]] to backwards, and abort these steps.
    3.88 +  [[rangeroot]], [[rangeset]] <var>range</var>'s [[rangestart]] and
    3.89 +  [[rangeend]] to (<var>parentNode</var>, <var>offset</var>), set the
    3.90 +  [[contextobject]]'s [[seldir]] to backwards, and abort these steps.
    3.91  
    3.92    <li>Let <var>anchor</var> and <var>focus</var> be the [[contextobject]]'s
    3.93    <span>anchor</span> and <span>focus</span>, and let <var>newFocus</var> be
    3.94 @@ -988,9 +981,9 @@
    3.95    <p>If <var>focus</var> and <var>newFocus</var> are the same, abort these
    3.96    steps.
    3.97  
    3.98 -  <li>Set <var>range</var>'s [[rangestart]] to <var>anchor</var> and its
    3.99 -  [[rangeend]] to <var>newFocus</var>, if <var>anchor</var> is [[bpbefore]] or
   3.100 -  equal to <var>newFocus</var>; or vice versa, if it's [[bpafter]].
   3.101 +  <li>[[Rangeset]] <var>range</var>'s [[rangestart]] to <var>anchor</var> and
   3.102 +  its [[rangeend]] to <var>newFocus</var>, if <var>anchor</var> is [[bpbefore]]
   3.103 +  or equal to <var>newFocus</var>; or vice versa, if it's [[bpafter]].
   3.104  
   3.105    <li>If <var>newFocus</var> is [[bpbefore]] <var>anchor</var>, set the
   3.106    [[contextobject]]'s [[seldir]] to backwards.  Otherwise, set it to forwards.
   3.107 @@ -1115,13 +1108,21 @@
   3.108  </div>
   3.109  
   3.110  <p>The <dfn
   3.111 -title=dom-Selection-selectAllChildren><code>selectAllChildren(<var>parentNode</var>)</code></dfn>
   3.112 -method must [[throw]] an [[InvalidNodeTypeError]] if <var>parentNode</var> is a
   3.113 -[[documenttype]].  Otherwise, it must set the [[contextobject]]'s [[range]] to
   3.114 -a new [[range]] whose [[startnode]] and [[endnode]] are <var>parentNode</var>,
   3.115 -whose [[startoffset]] is 0, and whose [[endoffset]] is the number of
   3.116 -<var>parentNode</var>'s [[children]]; then set the [[contextobject]]'s
   3.117 -[[seldir]] to forwards.
   3.118 +title=dom-Selection-selectAllChildren><code>selectAllChildren(<var>node</var>)</code></dfn>
   3.119 +method must run the following steps:
   3.120 +
   3.121 +<ol>
   3.122 +  <li>Let <var>range</var> be a new [[range]].
   3.123 +
   3.124 +  <li>[[Rangeset]] <var>range</var>'s [[rangestart]] to (<var>node</var>, 0).
   3.125 +
   3.126 +  <li>[[Rangeset]] <var>range</var>'s [[rangeend]] to (<var>node</var>, number
   3.127 +  of <var>node</var>'s [[children]]).
   3.128 +
   3.129 +  <li>Set the [[contextobject]]'s [[range]] to <var>range</var>.
   3.130 +
   3.131 +  <li>Set the [[contextobject]]'s [[seldir]] to <i title>forwards</i>.
   3.132 +</ol>
   3.133  
   3.134  <p>The <dfn
   3.135  title=dom-Selection-deleteFromDocument><code>deleteFromDocument()</code></dfn>