Make dt/dd work better for insertParagraph
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Sun, 29 May 2011 13:55:14 -0600
changeset 183 c879b966938b
parent 182 9447ac9f919c
child 184 593863f0275e
Make dt/dd work better for insertParagraph
editcommands.html
implementation.js
linebreaktest.html
source.html
--- a/editcommands.html	Sun May 29 13:43:27 2011 -0600
+++ b/editcommands.html	Sun May 29 13:55:14 2011 -0600
@@ -4237,14 +4237,26 @@
   the same as <var title="">range</var>'s, and whose <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-end title=concept-range-end>end</a> is
   (<var title="">container</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="">container</var>).
 
+  <li>Let <var title="">end of line</var> be true if <var title="">new line range</var> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#contained title=contained>contains</a> either nothing or a
+  single <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 false otherwise.
+
   <li>If the <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-element-local-name title=concept-element-local-name>local name</a> of <var title="">container</var> is "h1", "h2", "h3", "h4",
-  "h5", or "h6", and <var title="">new line range</var> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#contained title=contained>contains</a> either nothing or a single <code class=external data-anolis-spec=html title="the br element"><a href=http://www.whatwg.org/html/#the-br-element>br</a></code>, let
-  <var title="">new container name</var> be the <a href=#default-single-line-container-name>default single-line container
-  name</a>.
+  "h5", or "h6", and <var title="">end of line</var> is true, let <var title="">new container
+  name</var> be the <a href=#default-single-line-container-name>default single-line container name</a>.
   <!-- IE9 makes a new header if there's a trailing <br>.  Firefox 5.0a2,
   Chrome 13 dev, and Opera 11.10 do not, and I follow them, since it makes more
   sense (such a <br> is invisible). -->
 
+  <li>Otherwise, if the <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-element-local-name title=concept-element-local-name>local name</a> of <var title="">container</var> is "dt" and
+  <var title="">end of line</var> is true, let <var title="">new container name</var> be "dd".
+
+  <li>Otherwise, if the <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-element-local-name title=concept-element-local-name>local name</a> of <var title="">container</var> is "dd" and
+  <var title="">end of line</var> is true, let <var title="">new container name</var> be "dt".
+  <!-- These two follow Firefox 5.0a2.  IE9 and Chrome 13 dev act as though
+  these two lines were not present (they clone the existing element).  Opera
+  11.10 nests a <p> inside.  Firefox is the most useful, assuming a definition
+  list somehow winds up inside the content. -->
+
   <li>Otherwise, let <var title="">new container name</var> be the <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-element-local-name title=concept-element-local-name>local name</a> of
   <var title="">container</var>.
 
--- a/implementation.js	Sun May 29 13:43:27 2011 -0600
+++ b/implementation.js	Sun May 29 13:55:14 2011 -0600
@@ -3290,19 +3290,33 @@
 		newLineRange.setStart(range.startContainer, range.startOffset);
 		newLineRange.setEnd(container, getNodeLength(container));
 
+		// "Let end of line be true if new line range contains either nothing
+		// or a single br, and false otherwise."
+		var containedInNewLineRange = collectContainedNodes(newLineRange);
+		var endOfLine = !containedInNewLineRange.length
+			|| (containedInNewLineRange.length == 1
+			&& isHtmlElement(containedInNewLineRange[0], "br"));
+
 		// "If the local name of container is "h1", "h2", "h3", "h4", "h5", or
-		// "h6", and new line range contains either nothing or a single br, let
-		// new container name be the default single-line container name."
+		// "h6", and end of line is true, let new container name be the default
+		// single-line container name."
 		var newContainerName;
-		var containedInNewLineRange = collectContainedNodes(newLineRange);
 		if (/^H[1-6]$/.test(container.tagName)
-		&& (!containedInNewLineRange.length
-			|| (containedInNewLineRange.length == 1
-				&& isHtmlElement(containedInNewLineRange[0], "br")
-			)
-		)) {
+		&& endOfLine) {
 			newContainerName = defaultSingleLineContainerName;
 
+		// "Otherwise, if the local name of container is "dt" and end of line
+		// is true, let new container name be "dd"."
+		} else if (container.tagName == "DT"
+		&& endOfLine) {
+			newContainerName = "dd";
+
+		// "Otherwise, if the local name of container is "dd" and end of line
+		// is true, let new container name be "dt"."
+		} else if (container.tagName == "DD"
+		&& endOfLine) {
+			newContainerName = "dt";
+
 		// "Otherwise, let new container name be the local name of container."
 		} else {
 			newContainerName = container.tagName.toLowerCase();
--- a/linebreaktest.html	Sun May 29 13:43:27 2011 -0600
+++ b/linebreaktest.html	Sun May 29 13:55:14 2011 -0600
@@ -101,30 +101,39 @@
 
 	'[]foo',
 	'foo[]',
+	'foo[]<br>',
 	'foo[]bar',
 	'<address>[]foo</address>',
 	'<address>foo[]</address>',
+	'<address>foo[]<br></address>',
 	'<address>foo[]bar</address>',
 	'<div>[]foo</div>',
 	'<div>foo[]</div>',
+	'<div>foo[]<br></div>',
 	'<div>foo[]bar</div>',
 	'<dl><dt>[]foo<dd>bar</dl>',
 	'<dl><dt>foo[]<dd>bar</dl>',
+	'<dl><dt>foo[]<br><dd>bar</dl>',
 	'<dl><dt>foo[]bar<dd>baz</dl>',
 	'<dl><dt>foo<dd>[]bar</dl>',
 	'<dl><dt>foo<dd>bar[]</dl>',
+	'<dl><dt>foo<dd>bar[]<br></dl>',
 	'<dl><dt>foo<dd>bar[]baz</dl>',
 	'<h1>[]foo</h1>',
 	'<h1>foo[]</h1>',
+	'<h1>foo[]<br></h1>',
 	'<h1>foo[]bar</h1>',
 	'<ol><li>[]foo</ol>',
 	'<ol><li>foo[]</ol>',
+	'<ol><li>foo[]<br></ol>',
 	'<ol><li>foo[]bar</ol>',
 	'<p>[]foo</p>',
 	'<p>foo[]</p>',
+	'<p>foo[]<br></p>',
 	'<p>foo[]bar</p>',
 	'<pre>[]foo</pre>',
 	'<pre>foo[]</pre>',
+	'<pre>foo[]<br></pre>',
 	'<pre>foo[]bar</pre>',
 
 	'<ol><li>foo<li>{}<br></ol>',
@@ -137,10 +146,6 @@
 	'<h1>foo</h1>{}<p>bar</p>',
 	'<p>foo</p><h1>[bar]</h1><p>baz</p>',
 	'<p>foo</p>{<h1>bar</h1>}<p>baz</p>',
-
-	'foo<br>bar[]',
-	'foo[]<br>bar',
-	'foo<br>[]bar',
 ];
 
 var testsRunning = false;
--- a/source.html	Sun May 29 13:43:27 2011 -0600
+++ b/source.html	Sun May 29 13:55:14 2011 -0600
@@ -4272,15 +4272,27 @@
   the same as <var>range</var>'s, and whose [[rangeend]] is
   (<var>container</var>, [[nodelength]] of <var>container</var>).
 
+  <li>Let <var>end of line</var> be true if <var>new line range</var> <span
+  data-anolis-spec=domrange title=contained>contains</span> either nothing or a
+  single [[br]], and false otherwise.
+
   <li>If the [[localname]] of <var>container</var> is "h1", "h2", "h3", "h4",
-  "h5", or "h6", and <var>new line range</var> <span data-anolis-spec=domrange
-  title=contained>contains</span> either nothing or a single [[br]], let
-  <var>new container name</var> be the <span>default single-line container
-  name</span>.
+  "h5", or "h6", and <var>end of line</var> is true, let <var>new container
+  name</var> be the <span>default single-line container name</span>.
   <!-- IE9 makes a new header if there's a trailing <br>.  Firefox 5.0a2,
   Chrome 13 dev, and Opera 11.10 do not, and I follow them, since it makes more
   sense (such a <br> is invisible). -->
 
+  <li>Otherwise, if the [[localname]] of <var>container</var> is "dt" and
+  <var>end of line</var> is true, let <var>new container name</var> be "dd".
+
+  <li>Otherwise, if the [[localname]] of <var>container</var> is "dd" and
+  <var>end of line</var> is true, let <var>new container name</var> be "dt".
+  <!-- These two follow Firefox 5.0a2.  IE9 and Chrome 13 dev act as though
+  these two lines were not present (they clone the existing element).  Opera
+  11.10 nests a <p> inside.  Firefox is the most useful, assuming a definition
+  list somehow winds up inside the content. -->
+
   <li>Otherwise, let <var>new container name</var> be the [[localname]] of
   <var>container</var>.