Use DOM4's range set algorithm
authorAryeh Gregor <ayg@aryeh.name>
Thu, 12 Jan 2012 10:10:06 -0700
changeset 687 0ef300a5c14f
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
--- a/editing.html	Thu Jan 12 09:18:37 2012 -0700
+++ b/editing.html	Thu Jan 12 10:10:06 2012 -0700
@@ -860,6 +860,8 @@
 part of the selection's document?  Assuming it works, how is it presented to
 the user?
 
+<p class=XXX>What does <code title="">getSelection().getRangeAt(0).detach()</code> do?
+
 <dl class=domintro>
   <dt><var title="">selection</var> . <code title=dom-Selection-anchorNode><a href=#dom-selection-anchornode>anchorNode</a></code>
   <dd>
@@ -961,17 +963,10 @@
 are the same (including if both are null).  Otherwise it must return false.
 
 <p>The <dfn id=dom-selection-collapse title=dom-Selection-collapse><code>collapse(<var title="">parentNode</var>,
-<var title="">offset</var>)</code></dfn> method must run the following steps:
-
-<ol>
-  <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
-  <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
-  these steps.
-
-  <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
-  <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>,
-  <var title="">offset</var>).
-</ol>
+<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>,
+<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
+(<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
+<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>.
 
 <p class=comments>For collapseToStart/End, IE9 mutates the existing range,
 while Firefox 9.0a2 and Chrome 15 dev replace it with a new one.  The spec
@@ -980,15 +975,17 @@
 
 <p>The <dfn id=dom-selection-collapsetostart title=dom-Selection-collapseToStart><code>collapseToStart()</code></dfn> 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#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
-<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
-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
-<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>.
+<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,
+<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
+<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
+<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>.
 
 <p>The <dfn id=dom-selection-collapsetoend title=dom-Selection-collapseToEnd><code>collapseToEnd()</code></dfn> 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#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
-<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
-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
-<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>.
+<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,
+<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
+<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
+<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>.
 
 <p class=comments>Reverse-engineered circa January 2011.  IE doesn't support it, so I'm
 relying on Firefox (implemented extend() sometime before 2000) and WebKit
@@ -998,6 +995,8 @@
 <p>The <dfn id=dom-selection-extend title=dom-Selection-extend><code>extend(<var title="">parentNode</var>,
 <var title="">offset</var>)</code></dfn> method must run these steps:
 
+<p class=XXX>Does this mutate the existing range or make a new one?
+
 <ol>
   <li>
   <p class=comments>Gecko raises a nonstandard exception, WebKit initializes to
@@ -1007,12 +1006,6 @@
   <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
   <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.
 
-  <li>
-  <p class=comments>Gecko and WebKit agree on this, Opera ignores the call.
-
-  <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>,
-  <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.
-
   <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>.
 
   <li>
@@ -1022,9 +1015,9 @@
   case.)
 
   <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
-  <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
-  (<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
-  <a href=#concept-selection-dir title=concept-selection-dir>direction</a> to backwards, and abort these steps.
+  <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
+  <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
+  <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.
 
   <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
   <a href=#anchor>anchor</a> and <a href=#focus>focus</a>, and let <var title="">newFocus</var> be
@@ -1040,9 +1033,9 @@
   <p>If <var title="">focus</var> and <var title="">newFocus</var> are the same, abort these
   steps.
 
-  <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
-  <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
-  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>.
+  <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
+  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>
+  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>.
 
   <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
   <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.
@@ -1165,13 +1158,21 @@
 Opera 11.50 just does nothing in all my tests, as usual.
 </div>
 
-<p>The <dfn id=dom-selection-selectallchildren title=dom-Selection-selectAllChildren><code>selectAllChildren(<var title="">parentNode</var>)</code></dfn>
-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
-<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
-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>,
-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
-<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
-<a href=#concept-selection-dir title=concept-selection-dir>direction</a> to forwards.
+<p>The <dfn id=dom-selection-selectallchildren title=dom-Selection-selectAllChildren><code>selectAllChildren(<var title="">node</var>)</code></dfn>
+method must run the following steps:
+
+<ol>
+  <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>.
+
+  <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).
+
+  <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
+  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>).
+
+  <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>.
+
+  <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>.
+</ol>
 
 <p>The <dfn id=dom-selection-deletefromdocument title=dom-Selection-deleteFromDocument><code>deleteFromDocument()</code></dfn>
 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
--- a/preprocess	Thu Jan 12 09:18:37 2012 -0700
+++ b/preprocess	Thu Jan 12 10:10:06 2012 -0700
@@ -90,6 +90,7 @@
     'rangeend': '<span data-anolis-spec=dom title=concept-range-end>end</span>',
     'rangemutationrules': '<span data-anolis-spec=dom>range mutation rules</span>',
     'rangeroot': '<span data-anolis-spec=dom title=concept-range-root>root</span>',
+    'rangeset': '<span data-anolis-spec=dom title=concept-range-bp-set>set</span>',
     'rangestart': '<span data-anolis-spec=dom title=concept-range-start>start</span>',
     'remove': '<span data-anolis-spec=dom title=concept-node-remove>remove</span>',
     'removeallranges': '<code title=dom-Selection-removeAllRanges>removeAllRanges()</code>',
--- a/source.html	Thu Jan 12 09:18:37 2012 -0700
+++ b/source.html	Thu Jan 12 10:10:06 2012 -0700
@@ -806,6 +806,8 @@
 part of the selection's document?  Assuming it works, how is it presented to
 the user?
 
+<p class=XXX>What does {{code|getSelection().getRangeAt(0).detach()}} do?
+
 <dl class=domintro>
   <dt><var>selection</var> . <code title=dom-Selection-anchorNode>anchorNode</code>
   <dd>
@@ -907,17 +909,10 @@
 are the same (including if both are null).  Otherwise it must return false.
 
 <p>The <dfn title=dom-Selection-collapse><code>collapse(<var>parentNode</var>,
-<var>offset</var>)</code></dfn> method must run the following steps:
-
-<ol>
-  <li>If <var>offset</var> is greater than the [[length]] of
-  <var>parentNode</var>, [[throw]] an [[IndexSizeError]] exception and abort
-  these steps.
-
-  <li>Set the [[contextobject]]'s [[range]] to a new [[range]] object with
-  [[rangestart]] and [[rangeend]] both equal to (<var>parentNode</var>,
-  <var>offset</var>).
-</ol>
+<var>offset</var>)</code></dfn> method must create a new [[range]],
+[[rangeset]] both its [[rangestart]] and [[rangeend]] to
+(<var>parentNode</var>, <var>offset</var>), and set the [[contextobject]]'s
+[[range]] to the newly-created [[range]].
 
 <p class=comments>For collapseToStart/End, IE9 mutates the existing range,
 while Firefox 9.0a2 and Chrome 15 dev replace it with a new one.  The spec
@@ -927,16 +922,18 @@
 <p>The <dfn
 title=dom-Selection-collapseToStart><code>collapseToStart()</code></dfn> method
 must [[throw]] an [[InvalidStateError]] exception if the [[contextobject]]'s
-[[range]] is null.  Otherwise, it must set the [[contextobject]]'s [[range]] to
-a new [[range]] object with [[rangestart]] and [[rangeend]] both equal to the
-[[contextobject]]'s old [[range]]'s [[rangestart]].
+[[range]] is null.  Otherwise, it must create a new [[range]] object,
+[[rangeset]] both its [[rangestart]] and [[rangeend]] to the
+[[contextobject]]'s [[range]]'s [[rangestart]], and then set the
+[[contextobject]]'s [[range]] to the newly-created [[range]].
 
 <p>The <dfn
 title=dom-Selection-collapseToEnd><code>collapseToEnd()</code></dfn> method
 must [[throw]] an [[InvalidStateError]] exception if the [[contextobject]]'s
-[[range]] is null.  Otherwise, it must set the [[contextobject]]'s [[range]] to
-a new [[range]] object with [[rangestart]] and [[rangeend]] both equal to the
-[[contextobject]]'s old [[range]]'s [[rangeend]].
+[[range]] is null.  Otherwise, it must create a new [[range]] object,
+[[rangeset]] both its [[rangestart]] and [[rangeend]] to the
+[[contextobject]]'s [[range]]'s [[rangeend]], and then set the
+[[contextobject]]'s [[range]] to the newly-created [[range]].
 
 <p class=comments>Reverse-engineered circa January 2011.  IE doesn't support it, so I'm
 relying on Firefox (implemented extend() sometime before 2000) and WebKit
@@ -946,6 +943,8 @@
 <p>The <dfn title=dom-Selection-extend><code>extend(<var>parentNode</var>,
 <var>offset</var>)</code></dfn> method must run these steps:
 
+<p class=XXX>Does this mutate the existing range or make a new one?
+
 <ol>
   <li>
   <p class=comments>Gecko raises a nonstandard exception, WebKit initializes to
@@ -955,12 +954,6 @@
   <p>If the [[contextobject]]'s [[range]] is null, [[throw]] an
   [[InvalidStateError]] exception and abort these steps.
 
-  <li>
-  <p class=comments>Gecko and WebKit agree on this, Opera ignores the call.
-
-  <p>If <var>offset</var> is greater than <var>parentNode</var>'s [[length]],
-  [[throw]] an [[IndexSizeError]] exception and abort these steps.
-
   <li>Let <var>range</var> be the [[contextobject]]'s [[range]].
 
   <li>
@@ -970,9 +963,9 @@
   case.)
 
   <p>If <var>parentNode</var>'s [[root]] is not the same as <var>range</var>'s
-  [[rangeroot]], set <var>range</var>'s [[rangestart]] and [[rangeend]] to
-  (<var>parentNode</var>, <var>offset</var>), set the [[contextobject]]'s
-  [[seldir]] to backwards, and abort these steps.
+  [[rangeroot]], [[rangeset]] <var>range</var>'s [[rangestart]] and
+  [[rangeend]] to (<var>parentNode</var>, <var>offset</var>), set the
+  [[contextobject]]'s [[seldir]] to backwards, and abort these steps.
 
   <li>Let <var>anchor</var> and <var>focus</var> be the [[contextobject]]'s
   <span>anchor</span> and <span>focus</span>, and let <var>newFocus</var> be
@@ -988,9 +981,9 @@
   <p>If <var>focus</var> and <var>newFocus</var> are the same, abort these
   steps.
 
-  <li>Set <var>range</var>'s [[rangestart]] to <var>anchor</var> and its
-  [[rangeend]] to <var>newFocus</var>, if <var>anchor</var> is [[bpbefore]] or
-  equal to <var>newFocus</var>; or vice versa, if it's [[bpafter]].
+  <li>[[Rangeset]] <var>range</var>'s [[rangestart]] to <var>anchor</var> and
+  its [[rangeend]] to <var>newFocus</var>, if <var>anchor</var> is [[bpbefore]]
+  or equal to <var>newFocus</var>; or vice versa, if it's [[bpafter]].
 
   <li>If <var>newFocus</var> is [[bpbefore]] <var>anchor</var>, set the
   [[contextobject]]'s [[seldir]] to backwards.  Otherwise, set it to forwards.
@@ -1115,13 +1108,21 @@
 </div>
 
 <p>The <dfn
-title=dom-Selection-selectAllChildren><code>selectAllChildren(<var>parentNode</var>)</code></dfn>
-method must [[throw]] an [[InvalidNodeTypeError]] if <var>parentNode</var> is a
-[[documenttype]].  Otherwise, it must set the [[contextobject]]'s [[range]] to
-a new [[range]] whose [[startnode]] and [[endnode]] are <var>parentNode</var>,
-whose [[startoffset]] is 0, and whose [[endoffset]] is the number of
-<var>parentNode</var>'s [[children]]; then set the [[contextobject]]'s
-[[seldir]] to forwards.
+title=dom-Selection-selectAllChildren><code>selectAllChildren(<var>node</var>)</code></dfn>
+method must run the following steps:
+
+<ol>
+  <li>Let <var>range</var> be a new [[range]].
+
+  <li>[[Rangeset]] <var>range</var>'s [[rangestart]] to (<var>node</var>, 0).
+
+  <li>[[Rangeset]] <var>range</var>'s [[rangeend]] to (<var>node</var>, number
+  of <var>node</var>'s [[children]]).
+
+  <li>Set the [[contextobject]]'s [[range]] to <var>range</var>.
+
+  <li>Set the [[contextobject]]'s [[seldir]] to <i title>forwards</i>.
+</ol>
 
 <p>The <dfn
 title=dom-Selection-deleteFromDocument><code>deleteFromDocument()</code></dfn>