I don't like Comments
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 21 Jun 2011 12:30:52 -0600
changeset 306 fa09e48f4239
parent 305 1658d3f45c56
child 307 006aba32edd1
I don't like Comments

(let alone ProcessingInstructions)
editcommands.html
implementation.js
source.html
--- a/editcommands.html	Tue Jun 21 11:56:45 2011 -0600
+++ b/editcommands.html	Tue Jun 21 12:30:52 2011 -0600
@@ -3095,6 +3095,8 @@
 I'm using it mostly because it's convenient and seems relatively sensible.  If
 we really want to use it, we probably want to change its name.
 
+<p class=XXX>Needs nbsp magic.
+
 <ol>
   <li>If <var title="">range</var> is null, abort these steps and do nothing.
 
@@ -3152,7 +3154,8 @@
     with <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a> equal to <var title="">start offset</var>.
 
     <li>If <var title="">reference node</var> is a <a href=#prohibited-paragraph-child>prohibited paragraph
-    child</a> or an <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> with no <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>children</a>, break from this loop.
+    child</a> or an <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> with no <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>children</a>, or is neither an
+    <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> nor a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> node, break from this loop.
     <!--
     Don't descend into an element with no children, since then it won't get
     deleted even if it's selected.  Don't descend into a prohibited paragraph
@@ -3184,7 +3187,8 @@
     with <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a> equal to <var title="">end offset</var> minus one.
 
     <li>If <var title="">reference node</var> is a <a href=#prohibited-paragraph-child>prohibited paragraph
-    child</a> or an <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> with no <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>children</a>, break from this loop.
+    child</a> or an <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> with no <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>children</a>, or is neither an
+    <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> nor a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> node, break from this loop.
 
     <li>Set <var title="">end node</var> to <var title="">reference node</var> and <var title="">end
     offset</var> to the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-node-length title=concept-node-length>length</a> of <var title="">reference node</var>.
@@ -3194,14 +3198,13 @@
   node</var>, <var title="">start offset</var>), set <var title="">range</var>'s <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-end title=concept-range-end>end</a> to
   its <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-start title=concept-range-start>start</a> and abort these steps.
 
-  <li>If <var title="">start node</var> is a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> or <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#comment>Comment</a></code> node and <var title="">start
-  offset</var> is 0, set <var title="">start offset</var> to the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a> of <var title="">start
-  node</var>, then set <var title="">start node</var> to its <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a>.
-
-  <li>If <var title="">end node</var> is a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> or <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#comment>Comment</a></code> node and <var title="">end
-  offset</var> is its <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-node-length title=concept-node-length>length</a>, set <var title="">end offset</var> to one plus the
-  <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a> of <var title="">end node</var>, then set <var title="">end node</var> to its
-  <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a>.
+  <li>If <var title="">start node</var> is a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> node and <var title="">start offset</var>
+  is 0, set <var title="">start offset</var> to the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a> of <var title="">start node</var>,
+  then set <var title="">start node</var> to its <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a>.
+
+  <li>If <var title="">end node</var> is a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> node and <var title="">end offset</var> is
+  its <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-node-length title=concept-node-length>length</a>, set <var title="">end offset</var> to one plus the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a> of
+  <var title="">end node</var>, then set <var title="">end node</var> to its <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a>.
 
   <li>Set <var title="">range</var>'s <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-start title=concept-range-start>start</a> to (<var title="">start node</var>,
   <var title="">start offset</var>) and its <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-end title=concept-range-end>end</a> to (<var title="">end node</var>,
@@ -3262,19 +3265,19 @@
   <a href=#allowed-child>allowed child</a> of <var title="">end block</var>, or <var title="">end block</var>
   is a <code class=external data-anolis-spec=html title="the td element"><a href=http://www.whatwg.org/html/#the-td-element>td</a></code> or <code class=external data-anolis-spec=html title="the th element"><a href=http://www.whatwg.org/html/#the-th-element>th</a></code>, set <var title="">end block</var> to null.
 
-  <!-- This is based on deleteData() in DOM Range. -->
+  <!-- This is based on deleteContents() in DOM Range. -->
   <li>If <var title="">start node</var> and <var title="">end node</var> are the same, and
-  <var title="">start node</var> is an <a href=#editable>editable</a> <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> or <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#comment>Comment</a></code>
-  node, call <code class=external data-anolis-spec=domcore title=dom-CharacterData-deleteData><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-characterdata-deletedata>deleteData(<var title="">start offset</var>, <var title="">end offset</var>
-  &minus; <var title="">start offset</var>)</a></code> on <var title="">start node</var>.
+  <var title="">start node</var> is an <a href=#editable>editable</a> <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> node, call
+  <code class=external data-anolis-spec=domcore title=dom-CharacterData-deleteData><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-characterdata-deletedata>deleteData(<var title="">start offset</var>, <var title="">end offset</var> &minus;
+  <var title="">start offset</var>)</a></code> on <var title="">start node</var>.
 
   <li>Otherwise:
 
   <ol>
-    <li>If <var title="">start node</var> is an <a href=#editable>editable</a> <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> or
-    <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#comment>Comment</a></code> node, call <code class=external data-anolis-spec=domcore title=dom-CharacterData-deleteData><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-characterdata-deletedata>deleteData()</a></code> on it, with <var title="">start offset</var>
-    as the first argument and (<a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-node-length title=concept-node-length>length</a> of <var title="">start node</var> &minus;
-    <var title="">start offset</var>) as the second argument.
+    <li>If <var title="">start node</var> is an <a href=#editable>editable</a> <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> node,
+    call <code class=external data-anolis-spec=domcore title=dom-CharacterData-deleteData><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-characterdata-deletedata>deleteData()</a></code> on it, with <var title="">start offset</var> as the first
+    argument and (<a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-node-length title=concept-node-length>length</a> of <var title="">start node</var> &minus; <var title="">start
+    offset</var>) as the second argument.
 
     <li>Let <var title="">node list</var> be a list of <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>nodes</a>, initially empty.
 
@@ -3312,8 +3315,8 @@
       result as the last <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>child</a> of <var title="">parent</var>.
     </ol>
 
-    <li>If <var title="">end node</var> is an <a href=#editable>editable</a> <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> or
-    <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#comment>Comment</a></code> node, call <code class=external data-anolis-spec=domcore title=dom-CharacterData-deleteData><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-characterdata-deletedata>deleteData(0, <var title="">end offset</var>)</a></code> on it.
+    <li>If <var title="">end node</var> is an <a href=#editable>editable</a> <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> node, call
+    <code class=external data-anolis-spec=domcore title=dom-CharacterData-deleteData><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-characterdata-deletedata>deleteData(0, <var title="">end offset</var>)</a></code> on it.
   </ol>
 
   <!--
@@ -4303,8 +4306,6 @@
 
 <h3 id=the-delete-command><span class=secno>7.9 </span><dfn>The <code title="">delete</code> command</dfn></h3>
 
-<p class=XXX>Needs nbsp magic.
-
 <p><a href=#action>Action</a>:
 
 <ol>
@@ -4790,8 +4791,6 @@
 
 <h3 id=the-forwarddelete-command><span class=secno>7.11 </span><dfn>The <code title="">forwardDelete</code> command</dfn></h3>
 
-<p class=XXX>Needs nbsp magic.
-
 <p><a href=#action>Action</a>:
 <!-- Copy-pasted from delete, see there for comments. -->
 
--- a/implementation.js	Tue Jun 21 11:56:45 2011 -0600
+++ b/implementation.js	Tue Jun 21 12:30:52 2011 -0600
@@ -3626,10 +3626,13 @@
 		var referenceNode = startNode.childNodes[startOffset];
 
 		// "If reference node is a prohibited paragraph child or an Element
-		// with no children, break from this loop."
+		// with no children, or is neither an Element nor a Text node, break
+		// from this loop."
 		if (isProhibitedParagraphChild(referenceNode)
 		|| (referenceNode.nodeType == Node.ELEMENT_NODE
-		&& !referenceNode.hasChildNodes())) {
+		&& !referenceNode.hasChildNodes())
+		|| (referenceNode.nodeType != Node.ELEMENT_NODE
+		&& referenceNode.nodeType != Node.TEXT_NODE)) {
 			break;
 		}
 
@@ -3662,10 +3665,13 @@
 		var referenceNode = endNode.childNodes[endOffset - 1];
 
 		// "If reference node is a prohibited paragraph child or an Element
-		// with no children, break from this loop."
+		// with no children, or is neither an Element nor a Text node, break
+		// from this loop."
 		if (isProhibitedParagraphChild(referenceNode)
 		|| (referenceNode.nodeType == Node.ELEMENT_NODE
-		&& !referenceNode.hasChildNodes())) {
+		&& !referenceNode.hasChildNodes())
+		|| (referenceNode.nodeType != Node.ELEMENT_NODE
+		&& referenceNode.nodeType != Node.TEXT_NODE)) {
 			break;
 		}
 
@@ -3686,21 +3692,17 @@
 		return;
 	}
 
-	// "If start node is a Text or Comment node and start offset is 0, set
-	// start offset to the index of start node, then set start node to its
-	// parent."
-	if ((startNode.nodeType == Node.TEXT_NODE
-	|| startNode.nodeType == Node.COMMENT_NODE)
+	// "If start node is a Text node and start offset is 0, set start offset to
+	// the index of start node, then set start node to its parent."
+	if (startNode.nodeType == Node.TEXT_NODE
 	&& startOffset == 0) {
 		startOffset = getNodeIndex(startNode);
 		startNode = startNode.parentNode;
 	}
 
-	// "If end node is a Text or Comment node and end offset is its length, set
-	// end offset to one plus the index of end node, then set end node to its
-	// parent."
-	if ((endNode.nodeType == Node.TEXT_NODE
-	|| endNode.nodeType == Node.COMMENT_NODE)
+	// "If end node is a Text node and end offset is its length, set end offset
+	// to one plus the index of end node, then set end node to its parent."
+	if (endNode.nodeType == Node.TEXT_NODE
 	&& endOffset == getNodeLength(endNode)) {
 		endOffset = 1 + getNodeIndex(endNode);
 		endNode = endNode.parentNode;
@@ -3750,21 +3752,20 @@
 	}
 
 	// "If start node and end node are the same, and start node is an editable
-	// Text or Comment node, call deleteData(start offset, end offset − start
-	// offset) on start node."
+	// Text node, call deleteData(start offset, end offset − start offset) on
+	// start node."
 	if (startNode == endNode
 	&& isEditable(startNode)
-	&& (startNode.nodeType == Node.TEXT_NODE || startNode.nodeType == Node.COMMENT_NODE)) {
+	&& startNode.nodeType == Node.TEXT_NODE) {
 		startNode.deleteData(startOffset, endOffset - startOffset);
 
 	// "Otherwise:"
 	} else {
-		// "If start node is an editable Text or Comment node, call
-		// deleteData() on it, with start offset as the first argument and
-		// (length of start node − start offset) as the second argument."
+		// "If start node is an editable Text node, call deleteData() on it,
+		// with start offset as the first argument and (length of start node −
+		// start offset) as the second argument."
 		if (isEditable(startNode)
-		&& (startNode.nodeType == Node.TEXT_NODE
-		|| startNode.nodeType == Node.COMMENT_NODE)) {
+		&& startNode.nodeType == Node.TEXT_NODE) {
 			startNode.deleteData(startOffset, getNodeLength(startNode) - startOffset);
 		}
 
@@ -3812,11 +3813,10 @@
 			}
 		}
 
-		// "If end node is an editable Text or Comment node, call deleteData(0,
-		// end offset) on it."
+		// "If end node is an editable Text node, call deleteData(0, end
+		// offset) on it."
 		if (isEditable(endNode)
-		&& (endNode.nodeType == Node.TEXT_NODE
-		|| endNode.nodeType == Node.COMMENT_NODE)) {
+		&& endNode.nodeType == Node.TEXT_NODE) {
 			endNode.deleteData(0, endOffset);
 		}
 	}
--- a/source.html	Tue Jun 21 11:56:45 2011 -0600
+++ b/source.html	Tue Jun 21 12:30:52 2011 -0600
@@ -3080,6 +3080,8 @@
 I'm using it mostly because it's convenient and seems relatively sensible.  If
 we really want to use it, we probably want to change its name.
 
+<p class=XXX>Needs nbsp magic.
+
 <ol>
   <li>If <var>range</var> is null, abort these steps and do nothing.
 
@@ -3137,7 +3139,8 @@
     with [[index]] equal to <var>start offset</var>.
 
     <li>If <var>reference node</var> is a <span>prohibited paragraph
-    child</span> or an [[element]] with no [[children]], break from this loop.
+    child</span> or an [[element]] with no [[children]], or is neither an
+    [[element]] nor a [[text]] node, break from this loop.
     <!--
     Don't descend into an element with no children, since then it won't get
     deleted even if it's selected.  Don't descend into a prohibited paragraph
@@ -3169,7 +3172,8 @@
     with [[index]] equal to <var>end offset</var> minus one.
 
     <li>If <var>reference node</var> is a <span>prohibited paragraph
-    child</span> or an [[element]] with no [[children]], break from this loop.
+    child</span> or an [[element]] with no [[children]], or is neither an
+    [[element]] nor a [[text]] node, break from this loop.
 
     <li>Set <var>end node</var> to <var>reference node</var> and <var>end
     offset</var> to the [[nodelength]] of <var>reference node</var>.
@@ -3180,14 +3184,13 @@
   node</var>, <var>start offset</var>), set <var>range</var>'s [[rangeend]] to
   its [[rangestart]] and abort these steps.
 
-  <li>If <var>start node</var> is a [[text]] or [[comment]] node and <var>start
-  offset</var> is 0, set <var>start offset</var> to the [[index]] of <var>start
-  node</var>, then set <var>start node</var> to its [[parent]].
-
-  <li>If <var>end node</var> is a [[text]] or [[comment]] node and <var>end
-  offset</var> is its [[nodelength]], set <var>end offset</var> to one plus the
-  [[index]] of <var>end node</var>, then set <var>end node</var> to its
-  [[parent]].
+  <li>If <var>start node</var> is a [[text]] node and <var>start offset</var>
+  is 0, set <var>start offset</var> to the [[index]] of <var>start node</var>,
+  then set <var>start node</var> to its [[parent]].
+
+  <li>If <var>end node</var> is a [[text]] node and <var>end offset</var> is
+  its [[nodelength]], set <var>end offset</var> to one plus the [[index]] of
+  <var>end node</var>, then set <var>end node</var> to its [[parent]].
 
   <li>Set <var>range</var>'s [[rangestart]] to (<var>start node</var>,
   <var>start offset</var>) and its [[rangeend]] to (<var>end node</var>,
@@ -3248,19 +3251,19 @@
   <span>allowed child</span> of <var>end block</var>, or <var>end block</var>
   is a [[td]] or [[th]], set <var>end block</var> to null.
 
-  <!-- This is based on deleteData() in DOM Range. -->
+  <!-- This is based on deleteContents() in DOM Range. -->
   <li>If <var>start node</var> and <var>end node</var> are the same, and
-  <var>start node</var> is an <span>editable</span> [[text]] or [[comment]]
-  node, call [[deletedata|<var>start offset</var>, <var>end offset</var>
-  &minus; <var>start offset</var>]] on <var>start node</var>.
+  <var>start node</var> is an <span>editable</span> [[text]] node, call
+  [[deletedata|<var>start offset</var>, <var>end offset</var> &minus;
+  <var>start offset</var>]] on <var>start node</var>.
 
   <li>Otherwise:
 
   <ol>
-    <li>If <var>start node</var> is an <span>editable</span> [[text]] or
-    [[comment]] node, call [[deletedata|]] on it, with <var>start offset</var>
-    as the first argument and ([[nodelength]] of <var>start node</var> &minus;
-    <var>start offset</var>) as the second argument.
+    <li>If <var>start node</var> is an <span>editable</span> [[text]] node,
+    call [[deletedata|]] on it, with <var>start offset</var> as the first
+    argument and ([[nodelength]] of <var>start node</var> &minus; <var>start
+    offset</var>) as the second argument.
 
     <li>Let <var>node list</var> be a list of [[nodes]], initially empty.
 
@@ -3298,8 +3301,8 @@
       result as the last [[child]] of <var>parent</var>.
     </ol>
 
-    <li>If <var>end node</var> is an <span>editable</span> [[text]] or
-    [[comment]] node, call [[deletedata|0, <var>end offset</var>]] on it.
+    <li>If <var>end node</var> is an <span>editable</span> [[text]] node, call
+    [[deletedata|0, <var>end offset</var>]] on it.
   </ol>
 
   <!--
@@ -4305,8 +4308,6 @@
 
 <h3><dfn>The <code title>delete</code> command</dfn></h3>
 <!-- @{ -->
-<p class=XXX>Needs nbsp magic.
-
 <p><span>Action</span>:
 
 <ol>
@@ -4793,8 +4794,6 @@
 
 <h3><dfn>The <code title>forwardDelete</code> command</dfn></h3>
 <!-- @{ -->
-<p class=XXX>Needs nbsp magic.
-
 <p><span>Action</span>:
 <!-- Copy-pasted from delete, see there for comments. -->