Another delete tweak
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 07 Jun 2011 12:59:08 -0600
changeset 247 8b15f8fcc5c6
parent 246 9619abb1e583
child 248 31f2368d02c9
Another delete tweak

This one fixes the case '<p>foo<br><br></p>[]bar', which should be
'<p>foo<br>[]bar</p>' and not '<p>foo<br><br>[]bar</p>'.
editcommands.html
implementation.js
source.html
--- a/editcommands.html	Tue Jun 07 12:39:57 2011 -0600
+++ b/editcommands.html	Tue Jun 07 12:59:08 2011 -0600
@@ -2592,18 +2592,21 @@
   </ol>
 
   <li>If <var title="">node</var> has a <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="">offset</var>
-  &minus; 1:
+  &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 a <a href=#prohibited-paragraph-child>prohibited paragraph child</a>:
 
   <ol>
     <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><a href=#remove-extraneous-line-breaks-at-the-end-of>Remove extraneous line breaks at the end of</a> <var title="">start
+    <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>.
 
+    <li>If <var title="">start node</var>'s 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>, 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>, <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>) 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>).
+    (<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>
--- a/implementation.js	Tue Jun 07 12:39:57 2011 -0600
+++ b/implementation.js	Tue Jun 07 12:59:08 2011 -0600
@@ -3277,18 +3277,26 @@
 			return;
 		}
 
-		// "If node has a child with index offset − 1:"
+		// "If node has a child with index offset − 1, and that child is a
+		// prohibited paragraph child:"
 		if (0 <= offset -1
-		&& offset - 1 < node.childNodes.length) {
+		&& offset - 1 < node.childNodes.length
+		&& isProhibitedParagraphChild(node.childNodes[offset - 1])) {
 			// "Let start node be the child of node with index offset − 1."
 			var startNode = node.childNodes[offset - 1];
 
-			// "Remove extraneous line breaks at the end of start node."
-			removeExtraneousLineBreaksAtTheEndOf(startNode);
-
-			// "Delete the contents of the range with start (start node, length
-			// of start node) and end (node, offset)."
-			deleteContents(startNode, getNodeLength(startNode), node, offset);
+			// "Let start offset be the length of start node."
+			var startOffset = getNodeLength(startNode);
+
+			// "If start node's last child is a br, subtract one from start
+			// offset."
+			if (isHtmlElement(startNode.lastChild, "br")) {
+				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;
--- a/source.html	Tue Jun 07 12:39:57 2011 -0600
+++ b/source.html	Tue Jun 07 12:59:08 2011 -0600
@@ -2573,18 +2573,21 @@
   </ol>
 
   <li>If <var>node</var> has a [[child]] with [[index]] <var>offset</var>
-  &minus; 1:
+  &minus; 1, and that [[child]] is a <span>prohibited paragraph child</span>:
 
   <ol>
     <li>Let <var>start node</var> be the [[child]] of <var>node</var> with
     [[index]] <var>offset</var> &minus; 1.
 
-    <li><span>Remove extraneous line breaks at the end of</span> <var>start
+    <li>Let <var>start offset</var> be the [[nodelength]] of <var>start
     node</var>.
 
+    <li>If <var>start node</var>'s last [[child]] is a [[br]], subtract one
+    from <var>start offset</var>.
+
     <li><span>Delete the contents</span> of the [[range]] with [[rangestart]]
-    (<var>start node</var>, [[nodelength]] of <var>start node</var>) and
-    [[rangeend]] (<var>node</var>, <var>offset</var>).
+    (<var>start node</var>, <var>start offset</var>) and [[rangeend]]
+    (<var>node</var>, <var>offset</var>).
 
     <li>Abort these steps.
   </ol>