Yet another minor delete bug
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 07 Jun 2011 15:20:52 -0600
changeset 253 703ce5dc1c32
parent 252 2730e74c619a
child 254 d68602354ad5
Yet another minor delete bug

This one fixes the test case
"foo<br><br><table><tr><td>[]bar</table>baz", which previously deleted
one of the <br>'s (visibly!) but did nothing else, and now does nothing.
It also means "foo<br><table><tr><td>[]bar</table>baz" doesn't remove
the <br> anymore either, although that was invisible.
editcommands.html
implementation.js
source.html
--- a/editcommands.html	Tue Jun 07 15:01:02 2011 -0600
+++ b/editcommands.html	Tue Jun 07 15:20:52 2011 -0600
@@ -2571,12 +2571,6 @@
     <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><a href=#remove-extraneous-line-breaks-before>Remove extraneous line breaks before</a> <var title="">start
-    node</var>.
-
-    <p class=XXX>This removes the line break even if nothing winds up getting
-    merged (e.g., cursor at the start of a table).
-
     <li>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>.
 
     <li>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>.
@@ -2596,9 +2590,11 @@
     at all.
     -->
     <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>, 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>.
+    offset</var> minus one 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>, or 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> 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 the
+    <code class=external data-anolis-spec=html title="the br element"><a href=http://www.whatwg.org/html/#the-br-element>br</a></code>'s <code class=external data-anolis-spec=domcore title=dom-Node-previousSibling><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-previoussibling>previousSibling</a></code> is either 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 not an <a href=#inline-node>inline
+    node</a>, 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>.
 
     <!--
     Another special case:
--- a/implementation.js	Tue Jun 07 15:01:02 2011 -0600
+++ b/implementation.js	Tue Jun 07 15:20:52 2011 -0600
@@ -3294,9 +3294,6 @@
 				startNode = startNode.parentNode;
 			}
 
-			// "Remove extraneous line breaks before start node."
-			removeExtraneousLineBreaksBefore(startNode);
-
 			// "Set start offset to the index of start node."
 			startOffset = getNodeIndex(startNode);
 
@@ -3304,9 +3301,17 @@
 			startNode = startNode.parentNode;
 
 			// "If the child of start node with index start offset minus one is
-			// a br or hr, set node to start node and offset to start offset,
-			// then subtract one from start offset."
-			if (isHtmlElement(startNode.childNodes[startOffset - 1], ["br", "hr"])) {
+			// an hr, or the child is a br and the br's previousSibling is
+			// either a br or not an inline node, set node to start node and
+			// offset to start offset, then subtract one from start offset."
+			if (isHtmlElement(startNode.childNodes[startOffset - 1], "hr")
+			|| (
+				isHtmlElement(startNode.childNodes[startOffset - 1], "br")
+				&& (
+					isHtmlElement(startNode.childNodes[startOffset - 1].previousSibling, "br")
+					|| !isInlineNode(startNode.childNodes[startOffset - 1].previousSibling)
+				)
+			)) {
 				node = startNode;
 				offset = startOffset;
 				startOffset--;
--- a/source.html	Tue Jun 07 15:01:02 2011 -0600
+++ b/source.html	Tue Jun 07 15:20:52 2011 -0600
@@ -2551,12 +2551,6 @@
     [[index]] of <var>start node</var> and then set <var>start node</var> to
     its [[parent]].
 
-    <li><span>Remove extraneous line breaks before</span> <var>start
-    node</var>.
-
-    <p class=XXX>This removes the line break even if nothing winds up getting
-    merged (e.g., cursor at the start of a table).
-
     <li>Set <var>start offset</var> to the [[index]] of <var>start node</var>.
 
     <li>Set <var>start node</var> to its [[parent]].
@@ -2576,9 +2570,11 @@
     at all.
     -->
     <li>If the [[child]] of <var>start node</var> with [[index]] <var>start
-    offset</var> minus one is a [[br]] or [[hr]], 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>.
+    offset</var> minus one is an [[hr]], or the [[child]] is a [[br]] and the
+    [[br]]'s [[previoussibling]] is either a [[br]] or not an <span>inline
+    node</span>, 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>.
 
     <!--
     Another special case: