Handle some more cases for delete
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 07 Jun 2011 09:57:19 -0600
changeset 238 dfb268b4d33b
parent 237 1f3c9d03e7b4
child 239 2692317e2a27
Handle some more cases for delete
autoimplementation.html
editcommands.html
implementation.js
preprocess
source.html
--- a/autoimplementation.html	Mon Jun 06 16:11:16 2011 -0600
+++ b/autoimplementation.html	Tue Jun 07 09:57:19 2011 -0600
@@ -308,13 +308,25 @@
 		'foo<span style=display:none>bar</span>[]baz',
 		'fo&ouml;[]bar',
 		'foo&#x308;[]bar',
-		'<p>foo<p>[]bar',
+		'<p>foo</p><p>[]bar</p>',
+		'<p>foo</p>[]bar',
+		'foo<p>[]bar</p>',
+		'<p>foo<br></p><p>[]bar</p>',
+		'<p>foo<br></p>[]bar',
+		'foo<br><p>[]bar</p>',
 		'<div>foo</div><div>[]bar</div>',
 		'<pre>foo</pre>[]bar',
 		'foo<br>[]bar',
 		'foo<br><b>[]bar</b>',
 		'foo<hr>[]bar',
 		'<p>foo<hr><p>[]bar',
+		'<p>foo</p><br><p>[]bar</p>',
+		'<p>foo</p><br><br><p>[]bar</p>',
+		'<p>foo</p><img src=/img/lion.svg><p>[]bar',
+		'foo<img src=/img/lion.svg>[]bar',
+		'foo<span></span>[]bar',
+		'foo<span><span></span></span>[]bar',
+		'foo<quasit></quasit>[]bar',
 
 		'foo[bar]baz',
 
--- a/editcommands.html	Mon Jun 06 16:11:16 2011 -0600
+++ b/editcommands.html	Tue Jun 07 09:57:19 2011 -0600
@@ -38,7 +38,7 @@
 <body class=draft>
 <div class=head id=head>
 <h1>HTML Editing Commands</h1>
-<h2 class="no-num no-toc" id=work-in-progress-&mdash;-last-update-6-june-2011>Work in Progress &mdash; Last Update 6 June 2011</h2>
+<h2 class="no-num no-toc" id=work-in-progress-&mdash;-last-update-7-june-2011>Work in Progress &mdash; Last Update 7 June 2011</h2>
 <dl>
  <dt>Editor
  <dd>Aryeh Gregor &lt;ayg+spec@aryeh.name&gt;
@@ -2473,12 +2473,47 @@
   &minus; 1 and that <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> is an <code class=external data-anolis-spec=html title="the hr element"><a href=http://www.whatwg.org/html/#the-hr-element>hr</a></code>, set <var title="">node</var> to that
   <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>.
 
-  <li>If <var title="">node</var> is a <code class=external data-anolis-spec=html title="the br element"><a href=http://www.whatwg.org/html/#the-br-element>br</a></code> or <code class=external data-anolis-spec=html title="the hr element"><a href=http://www.whatwg.org/html/#the-hr-element>hr</a></code>, call
+  <li>If <var title="">node</var> is a <code class=external data-anolis-spec=html title="the br element"><a href=http://www.whatwg.org/html/#the-br-element>br</a></code> or <code class=external data-anolis-spec=html title="the hr element"><a href=http://www.whatwg.org/html/#the-hr-element>hr</a></code> or <code class=external data-anolis-spec=html title="the img element"><a href=http://www.whatwg.org/html/#the-img-element>img</a></code>, call
   <code class=external data-anolis-spec=domrange title=dom-Selection-collapse><a href=http://html5.org/specs/dom-range.html#dom-selection-collapse>collapse(<var title="">node</var>, 0)</a></code> on the <code class=external data-anolis-spec=domrange><a href=http://html5.org/specs/dom-range.html#selection>Selection</a></code>.  Then <a href=#delete-the-contents>delete
   the contents</a> of the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range title=concept-range>range</a> with <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=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a> of
   <var title="">node</var>, <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="">node</var>) and <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=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a>
   of <var title="">node</var>, 1 + <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="">node</var>) and abort these steps.
 
+  <li>If <var title="">node</var> is a <a href=#prohibited-paragraph-child>prohibited paragraph child</a> and
+  <var title="">offset</var> is zero:
+
+  <ol>
+    <li>Call <code class=external data-anolis-spec=domrange title=dom-Selection-collapse><a href=http://html5.org/specs/dom-range.html#dom-selection-collapse>collapse(<var title="">node</var>, <var title="">offset</var>)</a></code> on the
+    <code class=external data-anolis-spec=domrange><a href=http://html5.org/specs/dom-range.html#selection>Selection</a></code>.
+
+    <li>Let <var title="">start node</var> equal <var title="">node</var> and let <var title="">start
+    offset</var> equal <var title="">offset</var>.
+
+    <li>While <var title="">start offset</var> is zero, 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> and 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 the <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="">start node</var> with <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a> <var title="">start
+    offset</var> minus one is a <code class=external data-anolis-spec=html title="the br element"><a href=http://www.whatwg.org/html/#the-br-element>br</a></code> or <code class=external data-anolis-spec=html title="the hr element"><a href=http://www.whatwg.org/html/#the-hr-element>hr</a></code> or <code class=external data-anolis-spec=html title="the img element"><a href=http://www.whatwg.org/html/#the-img-element>img</a></code>, set
+    <var title="">node</var> to <var title="">start node</var> and <var title="">offset</var> to
+    <var title="">start offset</var>, then subtract one from <var title="">start offset</var>.
+
+    <li>Otherwise, 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-child title=concept-tree-child>child</a> with <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a>
+    <var title="">start offset</var> minus one, then set <var title="">start 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="">start node</var>.
+
+    <li>If <var title="">start node</var> is a <a href=#prohibited-paragraph-child>prohibited paragraph child</a>
+    whose 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> is a <code class=external data-anolis-spec=html title="the br element"><a href=http://www.whatwg.org/html/#the-br-element>br</a></code>, and <var title="">start offset</var> 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 <var title="">start node</var>, subtract one from <var title="">start
+    offset</var>.
+
+    <li><a href=#delete-the-contents>Delete the contents</a> of the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range title=concept-range>range</a> with <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-start title=concept-range-start>start</a>
+    (<var title="">start node</var>, <var title="">start offset</var>) and <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-end title=concept-range-end>end</a>
+    (<var title="">node</var>, <var title="">offset</var>).
+
+    <li>Abort these steps.
+  </ol>
+
   <li class=XXX>Lots more cases to handle.
 </ol>
 
--- a/implementation.js	Mon Jun 06 16:11:16 2011 -0600
+++ b/implementation.js	Tue Jun 07 09:57:19 2011 -0600
@@ -3169,16 +3169,66 @@
 			node = node.childNodes[offset - 1];
 		}
 
-		// "If node is a br or hr, call collapse(node, 0) on the Selection.
-		// Then delete the contents of the range with start (parent of node,
-		// index of node) and end (parent of node, 1 + index of node) and abort
-		// these steps."
-		if (isHtmlElement(node, ["br", "hr"])) {
+		// "If node is a br or hr or img, call collapse(node, 0) on the
+		// Selection.  Then delete the contents of the range with start (parent
+		// of node, index of node) and end (parent of node, 1 + index of node)
+		// and abort these steps."
+		if (isHtmlElement(node, ["br", "hr", "img"])) {
 			range.setStart(node, 0);
 			range.setEnd(node, 0);
 			deleteContents(node.parentNode, getNodeIndex(node), node.parentNode, 1 + getNodeIndex(node));
 			return;
 		}
+
+		// "If node is a prohibited paragraph child and offset is zero:"
+		if (isProhibitedParagraphChild(node)
+		&& offset == 0) {
+			// "Call collapse(node, offset) on the Selection."
+			range.setStart(node, offset);
+			range.setEnd(node, offset);
+
+			// "Let start node equal node and let start offset equal offset."
+			var startNode = node;
+			var startOffset = offset;
+
+			// "While start offset is zero, set start offset to the index of
+			// start node and then set start node to its parent."
+			while (startOffset == 0) {
+				startOffset = getNodeIndex(startNode);
+				startNode = startNode.parentNode;
+			}
+
+			// "If the child of start node with index start offset minus one is
+			// a br or hr or img, set node to start node and offset to start
+			// offset, then subtract one from start offset."
+			if (isHtmlElement(startNode.childNodes[startOffset - 1], ["br", "hr", "img"])) {
+				node = startNode;
+				offset = startOffset;
+				startOffset--;
+
+			// "Otherwise, set start node to its child with index start offset
+			// minus one, then set start offset to the length of start node."
+			} else {
+				startNode = startNode.childNodes[startOffset - 1];
+				startOffset = getNodeLength(startNode);
+			}
+
+			// "If start node is a prohibited paragraph child whose last child
+			// is a br, and start offset is the length of start node, subtract
+			// one from start offset."
+			if (isProhibitedParagraphChild(startNode)
+			&& isHtmlElement(startNode.lastChild, "br")
+			&& startOffset == getNodeLength(startNode)) {
+				startOffset--;
+			}
+
+			// "Delete the contents of the range with start (start node, start
+			// offset) and end (node, offset)."
+			deleteContents(startNode, startOffset, node, offset);
+
+			// "Abort these steps."
+			return;
+		}
 		break;
 
 		case "fontname":
--- a/preprocess	Mon Jun 06 16:11:16 2011 -0600
+++ b/preprocess	Tue Jun 07 09:57:19 2011 -0600
@@ -51,6 +51,7 @@
     'hr': '<code data-anolis-spec=html title="the hr element">hr</code>',
     'href': '<code data-anolis-spec=html title=attr-hyperlink-href>href</code>',
     'i': '<code data-anolis-spec=html title="the i element">i</code>',
+    'img': '<code data-anolis-spec=html title="the img element">img</code>',
     'index': '<span data-anolis-spec=domrange title=concept-indexof>index</span>',
     'lastchild': '<code data-anolis-spec=domcore title=dom-Node-lastChild>lastChild</code>',
     'li': '<code data-anolis-spec=html title="the li element">li</code>',
--- a/source.html	Mon Jun 06 16:11:16 2011 -0600
+++ b/source.html	Tue Jun 07 09:57:19 2011 -0600
@@ -2454,12 +2454,47 @@
   &minus; 1 and that [[child]] is an [[hr]], set <var>node</var> to that
   [[child]].
 
-  <li>If <var>node</var> is a [[br]] or [[hr]], call
+  <li>If <var>node</var> is a [[br]] or [[hr]] or [[img]], call
   [[selcollapse|<var>node</var>, 0]] on the [[selection]].  Then <span>delete
   the contents</span> of the [[range]] with [[rangestart]] ([[parent]] of
   <var>node</var>, [[index]] of <var>node</var>) and [[rangeend]] ([[parent]]
   of <var>node</var>, 1 + [[index]] of <var>node</var>) and abort these steps.
 
+  <li>If <var>node</var> is a <span>prohibited paragraph child</span> and
+  <var>offset</var> is zero:
+
+  <ol>
+    <li>Call [[selcollapse|<var>node</var>, <var>offset</var>]] on the
+    [[selection]].
+
+    <li>Let <var>start node</var> equal <var>node</var> and let <var>start
+    offset</var> equal <var>offset</var>.
+
+    <li>While <var>start offset</var> is zero, set <var>start offset</var> to
+    the [[index]] of <var>start node</var> and then set <var>start node</var>
+    to its [[parent]].
+
+    <li>If the [[child]] of <var>start node</var> with [[index]] <var>start
+    offset</var> minus one is a [[br]] or [[hr]] or [[img]], set
+    <var>node</var> to <var>start node</var> and <var>offset</var> to
+    <var>start offset</var>, then subtract one from <var>start offset</var>.
+
+    <li>Otherwise, set <var>start node</var> to its [[child]] with [[index]]
+    <var>start offset</var> minus one, then set <var>start offset</var> to the
+    [[nodelength]] of <var>start node</var>.
+
+    <li>If <var>start node</var> is a <span>prohibited paragraph child</span>
+    whose last [[child]] is a [[br]], and <var>start offset</var> is the
+    [[nodelength]] of <var>start node</var>, subtract one from <var>start
+    offset</var>.
+
+    <li><span>Delete the contents</span> of the [[range]] with [[rangestart]]
+    (<var>start node</var>, <var>start offset</var>) and [[rangeend]]
+    (<var>node</var>, <var>offset</var>).
+
+    <li>Abort these steps.
+  </ol>
+
   <li class=XXX>Lots more cases to handle.
 </ol>