Handle line breaks in insertText
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Sun, 19 Jun 2011 13:13:55 -0600
changeset 293 29ed14779368
parent 292 0042250f7e87
child 294 f3dac10677c0
Handle line breaks in insertText
editcommands.html
implementation.js
source.html
--- a/editcommands.html	Sun Jun 19 12:33:21 2011 -0600
+++ b/editcommands.html	Sun Jun 19 13:13:55 2011 -0600
@@ -5457,10 +5457,27 @@
   <li><a href=#delete-the-contents>Delete the contents</a> of the <a href=#active-range>active range</a>.
   <!-- Chrome 14 dev does this even if passed the empty string. -->
 
+  <li>While <var title="">value</var> contains a newline (U+0010):
+
+  <ol>
+    <li>Let <var title="">subvalue</var> be the empty string.
+
+    <li>While the first 16-bit element of <var title="">value</var> is not a newline
+    (0x0010), remove the first 16-bit element from <var title="">value</var> and append
+    it to <var title="">subvalue</var>.
+
+    <li>Take the <a href=#action>action</a> for <a href=#the-inserttext-command>the <code title="">insertText</code> command</a>, with <var title="">value</var> set to
+    <var title="">subvalue</var>.
+
+    <li>Remove the first 16-bit element from <var title="">value</var>.
+
+    <li>Take the <a href=#action>action</a> for <a href=#the-insertparagraph-command>the <code title="">insertParagraph</code> command</a>.
+  </ol>
+
   <li>If <var title="">value</var> is the empty string, abort these steps.
 
-  <p class=XXX>WebKit does magic for tabs, and actually handles newlines as
-  newlines.
+  <p class=XXX>WebKit does magic for tabs, wrapping them in a
+  whitespace-preserving span.
 
   <p class=XXX>This doesn't work well if the input contains things that aren't
   supposed to appear in HTML, like carriage returns or nulls.  Nor is it going
@@ -5759,9 +5776,7 @@
 with <var title="">value</var> equal to the text the user provided.  If the user inserts
 multiple characters at once or in quick succession, this specification does not
 define whether it is treated as one insertion or several consecutive
-insertions.  If the inserted text includes line breaks, the user agent must not
-process those as part of this paragraph, but instead according to the
-instructions above for processing line breaks.
+insertions.
 
 
 <h2 class=no-num id=acknowledgements>Acknowledgements</h2>
--- a/implementation.js	Sun Jun 19 12:33:21 2011 -0600
+++ b/implementation.js	Sun Jun 19 13:13:55 2011 -0600
@@ -5595,6 +5595,30 @@
 		// "Delete the contents of the active range."
 		deleteContents(getActiveRange());
 
+		// "While value contains a newline (U+0010):"
+		while (value.indexOf("\n") != -1) {
+			// "Let subvalue be the empty string."
+			var subvalue = "";
+
+			// "While the first 16-bit element of value is not a newline
+			// (0x0010), remove the first 16-bit element from value and append
+			// it to subvalue."
+			while (value[0] != "\n") {
+				subvalue += value[0];
+				value = value.slice(1);
+			}
+
+			// "Take the action for the insertText command, with value set to
+			// subvalue."
+			commands.inserttext.action(subvalue);
+
+			// "Remove the first 16-bit element from value."
+			value = value.slice(1);
+
+			// "Take the action for the insertParagraph command."
+			commands.insertparagraph.action();
+		}
+
 		// "If value is the empty string, abort these steps."
 		if (value == "") {
 			return;
--- a/source.html	Sun Jun 19 12:33:21 2011 -0600
+++ b/source.html	Sun Jun 19 13:13:55 2011 -0600
@@ -5476,10 +5476,29 @@
   <li><span>Delete the contents</span> of the <span>active range</span>.
   <!-- Chrome 14 dev does this even if passed the empty string. -->
 
+  <li>While <var>value</var> contains a newline (U+0010):
+
+  <ol>
+    <li>Let <var>subvalue</var> be the empty string.
+
+    <li>While the first 16-bit element of <var>value</var> is not a newline
+    (0x0010), remove the first 16-bit element from <var>value</var> and append
+    it to <var>subvalue</var>.
+
+    <li>Take the <span>action</span> for <span>the <code
+    title>insertText</code> command</span>, with <var>value</var> set to
+    <var>subvalue</var>.
+
+    <li>Remove the first 16-bit element from <var>value</var>.
+
+    <li>Take the <span>action</span> for <span>the <code
+    title>insertParagraph</code> command</span>.
+  </ol>
+
   <li>If <var>value</var> is the empty string, abort these steps.
 
-  <p class=XXX>WebKit does magic for tabs, and actually handles newlines as
-  newlines.
+  <p class=XXX>WebKit does magic for tabs, wrapping them in a
+  whitespace-preserving span.
 
   <p class=XXX>This doesn't work well if the input contains things that aren't
   supposed to appear in HTML, like carriage returns or nulls.  Nor is it going
@@ -5787,9 +5806,7 @@
 with <var>value</var> equal to the text the user provided.  If the user inserts
 multiple characters at once or in quick succession, this specification does not
 define whether it is treated as one insertion or several consecutive
-insertions.  If the inserted text includes line breaks, the user agent must not
-process those as part of this paragraph, but instead according to the
-instructions above for processing line breaks.
+insertions.
 <!-- @} -->
 
 <h2 class=no-num>Acknowledgements</h2>