Don't strip wrappers in empty blocks
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 08 Nov 2011 09:40:24 -0700
changeset 665 d461532af710
parent 664 b3afc97ff16e
child 666 0e6c95119654
Don't strip wrappers in empty blocks

See bug for info and reasoning. This changes the output of one
preexisting test for the better, as it happens. The new behavior more
closely matches WebKit, while the old behavior was more like Gecko.

Fixes: http://www.w3.org/Bugs/Public/show_bug.cgi?id=13831
conformancetest/data.js
editing.html
implementation.js
source.html
tests.js
--- a/conformancetest/data.js	Tue Nov 08 08:56:11 2011 -0700
+++ b/conformancetest/data.js	Tue Nov 08 09:40:24 2011 -0700
@@ -4367,6 +4367,70 @@
 	[["stylewithcss","true"],["delete",""]],
 	"<ul><li>foo{}</li></ul><ol><li>bar</li></ol>",
 	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
+["<p><b>[foo]</b>",
+	[["stylewithcss","false"],["delete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
+["<p><b>[foo]</b>",
+	[["stylewithcss","true"],["delete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
+["<p><quasit>[foo]</quasit>",
+	[["stylewithcss","false"],["delete",""]],
+	"<p><quasit>{}<br></quasit></p>",
+	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
+["<p><quasit>[foo]</quasit>",
+	[["stylewithcss","true"],["delete",""]],
+	"<p><quasit>{}<br></quasit></p>",
+	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
+["<p><b><i>[foo]</i></b>",
+	[["stylewithcss","false"],["delete",""]],
+	"<p><b><i>{}<br></i></b></p>",
+	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
+["<p><b><i>[foo]</i></b>",
+	[["stylewithcss","true"],["delete",""]],
+	"<p><b><i>{}<br></i></b></p>",
+	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
+["<p><b>{foo}</b>",
+	[["stylewithcss","false"],["delete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
+["<p><b>{foo}</b>",
+	[["stylewithcss","true"],["delete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
+["<p>{<b>foo</b>}",
+	[["stylewithcss","false"],["delete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
+["<p>{<b>foo</b>}",
+	[["stylewithcss","true"],["delete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
+["<p><b>f[]</b>",
+	[["stylewithcss","false"],["delete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
+["<p><b>f[]</b>",
+	[["stylewithcss","true"],["delete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
+["<b>[foo]</b>",
+	[["stylewithcss","false"],["delete",""]],
+	"<b>{}<br></b>",
+	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
+["<b>[foo]</b>",
+	[["stylewithcss","true"],["delete",""]],
+	"<b>{}<br></b>",
+	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
+["<div><b>[foo]</b></div>",
+	[["stylewithcss","false"],["delete",""]],
+	"<div><b>{}<br></b></div>",
+	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
+["<div><b>[foo]</b></div>",
+	[["stylewithcss","true"],["delete",""]],
+	"<div><b>{}<br></b></div>",
+	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
 ["foo[]bar",
 	[["stylewithcss","false"],["fontname","sans-serif"]],
 	"foo[]bar",
@@ -10719,6 +10783,70 @@
 	[["stylewithcss","true"],["forwarddelete",""]],
 	"<ul><li>foo</li></ul><p>{}bar</p>",
 	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<p><b>[foo]</b>",
+	[["stylewithcss","false"],["forwarddelete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<p><b>[foo]</b>",
+	[["stylewithcss","true"],["forwarddelete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<p><quasit>[foo]</quasit>",
+	[["stylewithcss","false"],["forwarddelete",""]],
+	"<p><quasit>{}<br></quasit></p>",
+	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<p><quasit>[foo]</quasit>",
+	[["stylewithcss","true"],["forwarddelete",""]],
+	"<p><quasit>{}<br></quasit></p>",
+	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<p><b><i>[foo]</i></b>",
+	[["stylewithcss","false"],["forwarddelete",""]],
+	"<p><b><i>{}<br></i></b></p>",
+	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<p><b><i>[foo]</i></b>",
+	[["stylewithcss","true"],["forwarddelete",""]],
+	"<p><b><i>{}<br></i></b></p>",
+	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<p><b>{foo}</b>",
+	[["stylewithcss","false"],["forwarddelete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<p><b>{foo}</b>",
+	[["stylewithcss","true"],["forwarddelete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<p>{<b>foo</b>}",
+	[["stylewithcss","false"],["forwarddelete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<p>{<b>foo</b>}",
+	[["stylewithcss","true"],["forwarddelete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<p><b>[]f</b>",
+	[["stylewithcss","false"],["forwarddelete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<p><b>[]f</b>",
+	[["stylewithcss","true"],["forwarddelete",""]],
+	"<p><b>{}<br></b></p>",
+	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<b>[foo]</b>",
+	[["stylewithcss","false"],["forwarddelete",""]],
+	"<b>{}<br></b>",
+	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<b>[foo]</b>",
+	[["stylewithcss","true"],["forwarddelete",""]],
+	"<b>{}<br></b>",
+	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<div><b>[foo]</b></div>",
+	[["stylewithcss","false"],["forwarddelete",""]],
+	"<div><b>{}<br></b></div>",
+	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
+["<div><b>[foo]</b></div>",
+	[["stylewithcss","true"],["forwarddelete",""]],
+	"<div><b>{}<br></b></div>",
+	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
 ["foo[]bar",
 	[["stylewithcss","false"],["hilitecolor","#00FFFF"]],
 	"foo[]bar",
@@ -28825,6 +28953,6 @@
 	{"delete":[false,false,"",false,false,""],"inserttext":[false,false,"",false,false,""]}],
 ["<blockquote><font color=blue>[foo]</font></blockquote>",
 	[["delete",""],["inserttext","a"]],
-	"<blockquote><font color=\"#0000ff\">a[]</font></blockquote>",
+	"<blockquote><font color=\"blue\">a[]</font></blockquote>",
 	{"delete":[false,false,"",false,false,""],"inserttext":[false,false,"",false,false,""]}]
 ]
--- a/editing.html	Tue Nov 08 08:56:11 2011 -0700
+++ b/editing.html	Tue Nov 08 09:40:24 2011 -0700
@@ -5512,6 +5512,15 @@
     <li>Remove <var title="">node</var> from <var title="">parent</var>.
 
     <li>
+    <p class=comments>Do this before stripping wrappers: see <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=13831">bug 13831</a>.
+
+    <p>If the <a href=#block-node-of>block node of</a> <var title="">parent</var> has no
+    <a href=#visible>visible</a> <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>children</a>, and <var title="">parent</var> is
+    <a href=#editable>editable</a> or an <a href=#editing-host>editing host</a>, call
+    <code class=external data-anolis-spec=dom title=dom-Document-createElement><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createelement>createElement("br")</a></code> on the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a> and append the result as
+    the last <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>child</a> of <var title="">parent</var>.
+
+    <li>
     <p class=comments>Taking insertText to test the case where strip wrappers
     is false, with value a: <code title="">&lt;p&gt;[foo&lt;b&gt;bar&lt;/b&gt;]baz</code> becomes
     <code title="">&lt;p&gt;a[]baz</code> per spec, in IE9, and in Chrome 14 dev.  Firefox 7.0a2
@@ -5537,11 +5546,6 @@
     content right afterward, like text or an image, but that new content will
     be inserted at the start node.  Wrappers in other places still need to be
     removed, because they would otherwise remain empty.
-
-    <li>If <var title="">parent</var> is <a href=#editable>editable</a> or an <a href=#editing-host>editing
-    host</a>, is not an <a href=#inline-node>inline node</a>, and has no <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>children</a>,
-    call <code class=external data-anolis-spec=dom title=dom-Document-createElement><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createelement>createElement("br")</a></code> on the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a> and append the result
-    as the last <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>child</a> of <var title="">parent</var>.
   </ol>
 
   <li>If <var title="">end node</var> is an <a href=#editable>editable</a> <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> node, call
--- a/implementation.js	Tue Nov 08 08:56:11 2011 -0700
+++ b/implementation.js	Tue Nov 08 09:40:24 2011 -0700
@@ -4656,6 +4656,14 @@
 		// "Remove node from parent."
 		parent_.removeChild(node);
 
+		// "If the block node of parent has no visible children, and parent is
+		// editable or an editing host, call createElement("br") on the context
+		// object and append the result as the last child of parent."
+		if (![].some.call(getBlockNodeOf(parent_).childNodes, isVisible)
+		&& (isEditable(parent_) || isEditingHost(parent_))) {
+			parent_.appendChild(document.createElement("br"));
+		}
+
 		// "If strip wrappers is true or parent is not an ancestor container of
 		// start node, while parent is an editable inline node with length 0,
 		// let grandparent be the parent of parent, then remove parent from
@@ -4670,15 +4678,6 @@
 				parent_ = grandparent;
 			}
 		}
-
-		// "If parent is editable or an editing host, is not an inline node,
-		// and has no children, call createElement("br") on the context object
-		// and append the result as the last child of parent."
-		if ((isEditable(parent_) || isEditingHost(parent_))
-		&& !isInlineNode(parent_)
-		&& !parent_.hasChildNodes()) {
-			parent_.appendChild(document.createElement("br"));
-		}
 	}
 
 	// "If end node is an editable Text node, call deleteData(0, end offset) on
--- a/source.html	Tue Nov 08 08:56:11 2011 -0700
+++ b/source.html	Tue Nov 08 09:40:24 2011 -0700
@@ -5563,6 +5563,16 @@
     <li>Remove <var>node</var> from <var>parent</var>.
 
     <li>
+    <p class=comments>Do this before stripping wrappers: see <a
+    href=http://www.w3.org/Bugs/Public/show_bug.cgi?id=13831>bug 13831</a>.
+
+    <p>If the <span>block node of</span> <var>parent</var> has no
+    <span>visible</span> [[children]], and <var>parent</var> is
+    <span>editable</span> or an <span>editing host</span>, call
+    [[createelement|"br"]] on the [[contextobject]] and append the result as
+    the last [[child]] of <var>parent</var>.
+
+    <li>
     <p class=comments>Taking insertText to test the case where strip wrappers
     is false, with value a: {{code<|p>[foo<b>bar</b>]baz}} becomes
     {{code|<p>a[]baz}} per spec, in IE9, and in Chrome 14 dev.  Firefox 7.0a2
@@ -5588,11 +5598,6 @@
     content right afterward, like text or an image, but that new content will
     be inserted at the start node.  Wrappers in other places still need to be
     removed, because they would otherwise remain empty.
-
-    <li>If <var>parent</var> is <span>editable</span> or an <span>editing
-    host</span>, is not an <span>inline node</span>, and has no [[children]],
-    call [[createelement|"br"]] on the [[contextobject]] and append the result
-    as the last [[child]] of <var>parent</var>.
   </ol>
 
   <li>If <var>end node</var> is an <span>editable</span> [[text]] node, call
--- a/tests.js	Tue Nov 08 08:56:11 2011 -0700
+++ b/tests.js	Tue Nov 08 09:40:24 2011 -0700
@@ -689,6 +689,16 @@
 		'<ol><li>foo</ol><p>{}<br></p><ul><li>bar</ul>',
 		'<ul><li>foo</ul>{}<br><ol><li>bar</ol>',
 		'<ul><li>foo</ul><p>{}<br></p><ol><li>bar</ol>',
+
+		// http://www.w3.org/Bugs/Public/show_bug.cgi?id=13831
+		'<p><b>[foo]</b>',
+		'<p><quasit>[foo]</quasit>',
+		'<p><b><i>[foo]</i></b>',
+		'<p><b>{foo}</b>',
+		'<p>{<b>foo</b>}',
+		'<p><b>f[]</b>',
+		'<b>[foo]</b>',
+		'<div><b>[foo]</b></div>',
 	],
 	//@}
 	fontname: [
@@ -1617,6 +1627,16 @@
 		'<ol><li>foo</ol><p>{}<br></p><ul><li>bar</ul>',
 		'<ul><li>foo</ul>{}<br><ol><li>bar</ol>',
 		'<ul><li>foo</ul><p>{}<br></p><ol><li>bar</ol>',
+
+		// http://www.w3.org/Bugs/Public/show_bug.cgi?id=13831
+		'<p><b>[foo]</b>',
+		'<p><quasit>[foo]</quasit>',
+		'<p><b><i>[foo]</i></b>',
+		'<p><b>{foo}</b>',
+		'<p>{<b>foo</b>}',
+		'<p><b>[]f</b>',
+		'<b>[foo]</b>',
+		'<div><b>[foo]</b></div>',
 	],
 	//@}
 	hilitecolor: [