selectAll shouldn't make an invalid selection
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Wed, 29 Jun 2011 11:40:29 -0600
changeset 345 2be533157a92
parent 344 1464ec42036a
child 346 5916e1f46d55
selectAll shouldn't make an invalid selection
editcommands.html
implementation.js
preprocess
source.html
--- a/editcommands.html	Wed Jun 29 11:34:25 2011 -0600
+++ b/editcommands.html	Wed Jun 29 11:40:29 2011 -0600
@@ -313,6 +313,9 @@
   <li>What happens if you do something like delete a selection or insert text
   or whatnot in the middle of a surrogate pair?  This could make the content
   not serialize through a character encoding change.
+
+  <li>Have to make sure that in all the places where we set a selection, it's
+  valid.
 </ul>
 
 <p class=XXX>A variety of other issues are also noted in the text, formatted
@@ -6694,11 +6697,11 @@
   <p class=XXX>Is this right even for documents whose root element is not an
   HTML element?
 
-  <li>If <var title="">target</var> is null, let <var title="">target</var> be the
-  <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#context-object>context object</a>.
-
-  <li>Call <code class=external data-anolis-spec=domrange title=dom-Document-getSelection><a href=http://html5.org/specs/dom-range.html#dom-document-getselection>getSelection()</a></code> on the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#context-object>context object</a>, and call <code class=external data-anolis-spec=domrange title=dom-Selection-selectAllChildren><a href=http://html5.org/specs/dom-range.html#dom-selection-selectallchildren>selectAllChildren(<var title="">target</var>)</a></code>
-  on the result.
+  <li>If <var title="">target</var> is null, call <code class=external data-anolis-spec=domrange title=dom-Document-getSelection><a href=http://html5.org/specs/dom-range.html#dom-document-getselection>getSelection()</a></code> on the
+  <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#context-object>context object</a>, and call <code class=external data-anolis-spec=domrange title=dom-Selection-removeAllRanges><a href=http://html5.org/specs/dom-range.html#dom-selection-removeallranges>removeAllRanges()</a></code> on the result.
+
+  <li>Otherwise, call <code class=external data-anolis-spec=domrange title=dom-Document-getSelection><a href=http://html5.org/specs/dom-range.html#dom-document-getselection>getSelection()</a></code> on the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#context-object>context object</a>, and call
+  <code class=external data-anolis-spec=domrange title=dom-Selection-selectAllChildren><a href=http://html5.org/specs/dom-range.html#dom-selection-selectallchildren>selectAllChildren(<var title="">target</var>)</a></code> on the result.
 </ol>
 
 
--- a/implementation.js	Wed Jun 29 11:34:25 2011 -0600
+++ b/implementation.js	Wed Jun 29 11:40:29 2011 -0600
@@ -6696,14 +6696,16 @@
 			target = document.documentElement;
 		}
 
-		// "If target is null, let target be the context object."
+		// "If target is null, call getSelection() on the context object, and
+		// call removeAllRanges() on the result."
 		if (!target) {
-			target = document;
-		}
-
-		// "Call getSelection() on the context object, and call
+			getSelection().removeAllRanges();
+
+		// "Otherwise, call getSelection() on the context object, and call
 		// selectAllChildren(target) on the result."
-		getSelection().selectAllChildren(target);
+		} else {
+			getSelection().selectAllChildren(target);
+		}
 	}
 };
 //@}
--- a/preprocess	Wed Jun 29 11:34:25 2011 -0600
+++ b/preprocess	Wed Jun 29 11:40:29 2011 -0600
@@ -79,6 +79,7 @@
     'rangemutationrules': '<span data-anolis-spec=domrange>range mutation rules</span>',
     'rangeroot': '<span data-anolis-spec=domrange title=concept-range-root>root</span>',
     'rangestart': '<span data-anolis-spec=domrange title=concept-range-start>start</span>',
+    'removeallranges': '<code data-anolis-spec=domrange title=dom-Selection-removeAllRanges>removeAllRanges()</code>',
     's': '<code data-anolis-spec=html title="the s element">s</code>',
     'selection': '<code data-anolis-spec=domrange>Selection</code>',
     'sibling': '<span data-anolis-spec=domcore title=concept-tree-sibling>sibling</span>',
@@ -129,6 +130,7 @@
     'insertnode': '<code data-anolis-spec=domrange title=dom-Range-insertNode>insertNode(\\1)</code>',
     'replacedata': '<code data-anolis-spec=domcore title=dom-CharacterData-replaceData>replaceData(\\1)</code>',
     'selcollapse': '<code data-anolis-spec=domrange title=dom-Selection-collapse>collapse(\\1)</code>',
+    'selectallchildren': '<code data-anolis-spec=domrange title=dom-Selection-selectAllChildren>selectAllChildren(\\1)</code>',
     'setattribute': '<code data-anolis-spec=domcore title=dom-Element-setAttribute>setAttribute(\\1)</code>',
 }
 
--- a/source.html	Wed Jun 29 11:34:25 2011 -0600
+++ b/source.html	Wed Jun 29 11:40:29 2011 -0600
@@ -246,6 +246,9 @@
   <li>What happens if you do something like delete a selection or insert text
   or whatnot in the middle of a surrogate pair?  This could make the content
   not serialize through a character encoding change.
+
+  <li>Have to make sure that in all the places where we set a selection, it's
+  valid.
 </ul>
 
 <p class=XXX>A variety of other issues are also noted in the text, formatted
@@ -6725,13 +6728,11 @@
   <p class=XXX>Is this right even for documents whose root element is not an
   HTML element?
 
-  <li>If <var>target</var> is null, let <var>target</var> be the
-  [[contextobject]].
-
-  <li>Call [[getselection]] on the [[contextobject]], and call <code
-  data-anolis-spec=domrange
-  title=dom-Selection-selectAllChildren>selectAllChildren(<var>target</var>)</code>
-  on the result.
+  <li>If <var>target</var> is null, call [[getselection]] on the
+  [[contextobject]], and call [[removeallranges]] on the result.
+
+  <li>Otherwise, call [[getselection]] on the [[contextobject]], and call
+  [[selectallchildren|<var>target</var>]] on the result.
 </ol>
 <!-- @} -->