Fix an insertText bug that's not so hard
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Mon, 20 Jun 2011 15:48:05 -0600
changeset 302 971ee4506a58
parent 301 6583685ff9c9
child 303 6fadee6e054c
Fix an insertText bug that's not so hard

Just removing extraneous <br>. Of course, this breaks if we added a
collapsed whitespace node, but that's a separate bug.
editcommands.html
implementation.js
source.html
tests.js
--- a/editcommands.html	Mon Jun 20 15:21:57 2011 -0600
+++ b/editcommands.html	Mon Jun 20 15:48:05 2011 -0600
@@ -5589,6 +5589,11 @@
     <li>Abort these steps.
   </ol>
 
+  <!-- If some text is inserted into <p><br></p> or similar, we no longer need
+  the <br>. -->
+  <li>If <var title="">node</var> has only one <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>, which is a <a href=#collapsed-line-break>collapsed
+  line break</a>, remove its <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> from it.
+
   <li>Let <var title="">text</var> be the result of calling <code class=external data-anolis-spec=domcore title=dom-Document-createTextNode><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createtextnode>createTextNode(<var title="">value</var>)</a></code> on
   the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#context-object>context object</a>.
 
--- a/implementation.js	Mon Jun 20 15:21:57 2011 -0600
+++ b/implementation.js	Mon Jun 20 15:48:05 2011 -0600
@@ -5750,6 +5750,13 @@
 			return;
 		}
 
+		// "If node has only one child, which is a collapsed line break, remove
+		// its child from it."
+		if (node.childNodes.length == 1
+		&& isCollapsedLineBreak(node.firstChild)) {
+			node.removeChild(node.firstChild);
+		}
+
 		// "Let text be the result of calling createTextNode(value) on the
 		// context object."
 		var text = document.createTextNode(value);
--- a/source.html	Mon Jun 20 15:21:57 2011 -0600
+++ b/source.html	Mon Jun 20 15:48:05 2011 -0600
@@ -5608,6 +5608,11 @@
     <li>Abort these steps.
   </ol>
 
+  <!-- If some text is inserted into <p><br></p> or similar, we no longer need
+  the <br>. -->
+  <li>If <var>node</var> has only one [[child]], which is a <span>collapsed
+  line break</span>, remove its [[child]] from it.
+
   <li>Let <var>text</var> be the result of calling <code
   data-anolis-spec=domcore
   title=dom-Document-createTextNode>createTextNode(<var>value</var>)</code> on
--- a/tests.js	Mon Jun 20 15:21:57 2011 -0600
+++ b/tests.js	Mon Jun 20 15:48:05 2011 -0600
@@ -1841,6 +1841,9 @@
 		[' ', '<span style=white-space:pre-wrap>[]foo</span>'],
 		[' ', '<span style=white-space:pre-wrap>foo []bar</span>'],
 
+		[' ', '{}<br>'],
+		[' ', '<p>{}<br>'],
+
 		['   ', 'foo[]'],
 
 		'foo[]bar',
@@ -1861,6 +1864,7 @@
 		'<a href=/>foo</a>[]bar',
 		'<p>fo[o<p>b]ar',
 		'<p>fo[o<p>bar<p>b]az',
+		'{}<br>',
 		'<p>{}<br>',
 		'<p><span>{}<br></span>',
 	],