Yet more delete refinement
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 07 Jun 2011 13:51:26 -0600
changeset 249 6a1817dbf0eb
parent 248 31f2368d02c9
child 250 2f6bc0e1d5e0
Yet more delete refinement
editcommands.html
implementation.js
source.html
tests.js
--- a/editcommands.html	Tue Jun 07 13:25:30 2011 -0600
+++ b/editcommands.html	Tue Jun 07 13:51:26 2011 -0600
@@ -2600,6 +2600,13 @@
     <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>While <var title="">start node</var> is a <a href=#prohibited-paragraph-child>prohibited paragraph
+    child</a> whose <code class=external data-anolis-spec=domcore title=dom-Node-lastChild><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-lastchild>lastChild</a></code> is a <a href=#prohibited-paragraph-child>prohibited paragraph
+    child</a>, 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>, set <var title="">start node</var> to its <code class=external data-anolis-spec=domcore title=dom-Node-lastChild><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-lastchild>lastChild</a></code> and
+    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
@@ -2629,6 +2636,9 @@
     <li>Let <var title="">start node</var> be 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="">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="">offset</var> &minus; 1.
 
+    <li>While <var title="">start node</var>'s <code class=external data-anolis-spec=domcore title=dom-Node-lastChild><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-lastchild>lastChild</a></code> is a <a href=#prohibited-paragraph-child>prohibited
+    paragraph child</a>, set <var title="">start node</var> to its <code class=external data-anolis-spec=domcore title=dom-Node-lastChild><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-lastchild>lastChild</a></code>.
+
     <li>Let <var title="">start offset</var> be 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>.
 
--- a/implementation.js	Tue Jun 07 13:25:30 2011 -0600
+++ b/implementation.js	Tue Jun 07 13:51:26 2011 -0600
@@ -3304,6 +3304,17 @@
 				startOffset = getNodeLength(startNode);
 			}
 
+			// "While start node is a prohibited paragraph child whose
+			// lastChild is a prohibited paragraph child, and start offset is
+			// the length of start node, set start node to its lastChild and
+			// then set start offset to the length of start node."
+			while (isProhibitedParagraphChild(startNode)
+			&& isProhibitedParagraphChild(startNode.lastChild)
+			&& startOffset == getNodeLength(startNode)) {
+				startNode = startNode.lastChild;
+				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."
@@ -3329,6 +3340,12 @@
 			// "Let start node be the child of node with index offset − 1."
 			var startNode = node.childNodes[offset - 1];
 
+			// "While start node's lastChild is a prohibited paragraph child,
+			// set start node to its lastChild."
+			while (isProhibitedParagraphChild(startNode.lastChild)) {
+				startNode = startNode.lastChild;
+			}
+
 			// "Let start offset be the length of start node."
 			var startOffset = getNodeLength(startNode);
 
--- a/source.html	Tue Jun 07 13:25:30 2011 -0600
+++ b/source.html	Tue Jun 07 13:51:26 2011 -0600
@@ -2581,6 +2581,13 @@
     <var>start offset</var> minus one, then set <var>start offset</var> to the
     [[nodelength]] of <var>start node</var>.
 
+    <li>While <var>start node</var> is a <span>prohibited paragraph
+    child</span> whose [[lastchild]] is a <span>prohibited paragraph
+    child</span>, and <var>start offset</var> is the [[nodelength]] of
+    <var>start node</var>, set <var>start node</var> to its [[lastchild]] and
+    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
@@ -2610,6 +2617,9 @@
     <li>Let <var>start node</var> be the [[child]] of <var>node</var> with
     [[index]] <var>offset</var> &minus; 1.
 
+    <li>While <var>start node</var>'s [[lastchild]] is a <span>prohibited
+    paragraph child</span>, set <var>start node</var> to its [[lastchild]].
+
     <li>Let <var>start offset</var> be the [[nodelength]] of <var>start
     node</var>.
 
--- a/tests.js	Tue Jun 07 13:25:30 2011 -0600
+++ b/tests.js	Tue Jun 07 13:51:26 2011 -0600
@@ -225,12 +225,14 @@
 	// PropertyName to be any IdentifierName, and see 7.6 which defines
 	// IdentifierName to include ReservedWord; Identifier excludes it.
 	"delete": [
+		// Collapsed selection
 		'foo[]bar',
 		'<span>foo</span>{}<span>bar</span>',
 		'<span>foo[</span><span>]bar</span>',
 		'foo<span style=display:none>bar</span>[]baz',
 		'fo&ouml;[]bar',
 		'foo&#x308;[]bar',
+
 		'<p>foo</p><p>[]bar</p>',
 		'<p>foo</p>[]bar',
 		'foo<p>[]bar</p>',
@@ -240,8 +242,16 @@
 		'<p>foo<br><br></p><p>[]bar</p>',
 		'<p>foo<br><br></p>[]bar',
 		'foo<br><br><p>[]bar</p>',
+
+		'<div><p>foo</p></div><p>[]bar</p>',
+		'<p>foo</p><div><p>[]bar</p></div>',
+		'<div><p>foo</p></div><div><p>[]bar</p></div>',
+		'<div><p>foo</p></div>[]bar',
+		'foo<div><p>[]bar</p></div>',
+
 		'<div>foo</div><div>[]bar</div>',
 		'<pre>foo</pre>[]bar',
+
 		'foo<br>[]bar',
 		'foo<br><b>[]bar</b>',
 		'foo<hr>[]bar',
@@ -250,6 +260,29 @@
 		'<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',
+		'<a href=/>foo</a>[]bar',
+		'foo<a href=/>[]bar</a>',
+
+		'foo<table><tr><td>[]bar</table>baz',
+		'foo<table><tr><td>bar</table>[]baz',
+		'<p>foo<table><tr><td>[]bar</table><p>baz',
+		'<p>foo<table><tr><td>bar</table><p>[]baz',
+		'<table><tr><td>foo<td>[]bar</table>',
+		'<table><tr><td>foo<tr><td>[]bar</table>',
+
+		'foo<br><table><tr><td>[]bar</table>baz',
+		'foo<table><tr><td>bar<br></table>[]baz',
+		'<p>foo<br><table><tr><td>[]bar</table><p>baz',
+		'<p>foo<table><tr><td>bar<br></table><p>[]baz',
+		'<table><tr><td>foo<br><td>[]bar</table>',
+		'<table><tr><td>foo<br><tr><td>[]bar</table>',
+
+		'foo<br><br><table><tr><td>[]bar</table>baz',
+		'foo<table><tr><td>bar<br><br></table>[]baz',
+		'<p>foo<br><br><table><tr><td>[]bar</table><p>baz',
+		'<p>foo<table><tr><td>bar<br><br></table><p>[]baz',
+		'<table><tr><td>foo<br><br><td>[]bar</table>',
+		'<table><tr><td>foo<br><br><tr><td>[]bar</table>',
 
 		// Invisible stuff
 		'foo<span></span>[]bar',
@@ -259,6 +292,7 @@
 		'<span>foo<span></span></span>[]bar',
 		'foo<span></span><span>[]bar</span>',
 
+		// Uncollapsed selection
 		'foo[bar]baz',
 
 		'foo<b>[bar]</b>baz',