Regularize insertHorizontalRule deletion
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Thu, 26 May 2011 10:51:05 -0600
changeset 178 8400d57ca296
parent 177 19c0d176432e
child 179 80d0b644c1f8
Regularize insertHorizontalRule deletion

Previously it would treat <b>[foo]</b> and {<b>foo</b>} differently, for
instance. The new behavior seems to match Firefox.
autoimplementation.html
editcommands.html
implementation.js
source.html
--- a/autoimplementation.html	Thu May 26 10:38:25 2011 -0600
+++ b/autoimplementation.html	Thu May 26 10:51:05 2011 -0600
@@ -861,7 +861,14 @@
 		'<b id=abc>foo[]bar</b>',
 		["abc", 'foo[bar]baz'],
 		'foo[bar]baz',
+
+		'foo<b>[bar]</b>baz',
 		'foo<b>{bar}</b>baz',
+		'foo{<b>bar</b>}baz',
+		'<p>foo<p>[bar]<p>baz',
+		'<p>foo<p>{bar}<p>baz',
+		'<p>foo{<p>bar</p>}<p>baz',
+
 		'<p>foo[bar]baz</p>',
 		'<p id=abc>foo[bar]baz</p>',
 		'<h1>foo[bar]baz</h1>',
--- a/editcommands.html	Thu May 26 10:38:25 2011 -0600
+++ b/editcommands.html	Thu May 26 10:51:05 2011 -0600
@@ -4037,8 +4037,19 @@
 <ol>
   <li>Let <var title="">range</var> be the <a href=#active-range>active range</a>.
 
+  <li>While <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> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-offset title=concept-boundary-point-offset>offset</a> is 0 and 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> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a>'s
+  <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> is not null, 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 (<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>
+  of <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-start title=concept-range-start>start</a> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a>, <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a> of <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-start title=concept-range-start>start</a> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a>).
+
+  <li>While <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> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-offset title=concept-boundary-point-offset>offset</a> is 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 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> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a>, 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> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a>'s <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> is not null, 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 (<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> of <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-end title=concept-range-end>end</a> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a>, 1 + <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a>
+  of <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-start title=concept-range-start>start</a> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a>).
+
   <li>Run <code class=external data-anolis-spec=domrange title=dom-Range-deleteContents><a href=http://html5.org/specs/dom-range.html#dom-range-deletecontents>deleteContents()</a></code> on <var title="">range</var>.
 
+  <p class=XXX>This might blow up non-contenteditable stuff.
+
   <li>Let <var title="">hr</var> be the result of calling <code class=external data-anolis-spec=domcore title=dom-Document-createElement><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createelement>createElement("hr")</a></code> on the
   <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#context-object>context object</a>.
 
--- a/implementation.js	Thu May 26 10:38:25 2011 -0600
+++ b/implementation.js	Thu May 26 10:51:05 2011 -0600
@@ -3084,6 +3084,22 @@
 		break;
 
 		case "inserthorizontalrule":
+		// "While range's start offset is 0 and its start node's parent is not
+		// null, set range's start to (parent of start node, index of start
+		// node)."
+		while (range.startOffset == 0
+		&& range.startContainer.parentNode) {
+			range.setStart(range.startContainer.parentNode, getNodeIndex(range.startContainer));
+		}
+
+		// "While range's end offset is the length of its end node, and its end
+		// node's parent is not null, set range's end to (parent of end node, 1
+		// + index of start node)."
+		while (range.endOffset == getNodeLength(range.endContainer)
+		&& range.endContainer.parentNode) {
+			range.setEnd(range.endContainer.parentNode, 1 + getNodeIndex(range.endContainer));
+		}
+
 		// "Run deleteContents() on the range."
 		range.deleteContents();
 
--- a/source.html	Thu May 26 10:38:25 2011 -0600
+++ b/source.html	Thu May 26 10:51:05 2011 -0600
@@ -4064,9 +4064,20 @@
 <ol>
   <li>Let <var>range</var> be the <span>active range</span>.
 
+  <li>While <var>range</var>'s [[startoffset]] is 0 and its [[startnode]]'s
+  [[parent]] is not null, set <var>range</var>'s [[rangestart]] to ([[parent]]
+  of [[startnode]], [[index]] of [[startnode]]).
+
+  <li>While <var>range</var>'s [[endoffset]] is the [[nodelength]] of its
+  [[endnode]], and its [[endnode]]'s [[parent]] is not null, set
+  <var>range</var>'s [[rangeend]] to ([[parent]] of [[endnode]], 1 + [[index]]
+  of [[startnode]]).
+
   <li>Run <code data-anolis-spec=domrange
   title=dom-Range-deleteContents>deleteContents()</code> on <var>range</var>.
 
+  <p class=XXX>This might blow up non-contenteditable stuff.
+
   <li>Let <var>hr</var> be the result of calling <code
   data-anolis-spec=domcore
   title=dom-Document-createElement>createElement("hr")</code> on the