Don't call execCommand() recursively
authorAryeh Gregor <ayg@aryeh.name>
Mon, 12 Mar 2012 13:35:59 -0600
changeset 714 9b1189899718
parent 713 20a863fefa64
child 715 98d33b30b6ab
Don't call execCommand() recursively

Now this makes a difference, because it will fire extra events.
editing.html
implementation.js
source.html
--- a/editing.html	Mon Mar 12 13:35:46 2012 -0600
+++ b/editing.html	Mon Mar 12 13:35:59 2012 -0600
@@ -67,7 +67,7 @@
 <body class=draft>
 <div class=head id=head>
 <h1>HTML Editing APIs</h1>
-<h2 class="no-num no-toc" id=work-in-progress-&mdash;-last-update-5-march-2012>Work in Progress &mdash; Last Update 5 March 2012</h2>
+<h2 class="no-num no-toc" id=work-in-progress-&mdash;-last-update-12-march-2012>Work in Progress &mdash; Last Update 12 March 2012</h2>
 <dl>
  <dt>Editor
  <dd>Aryeh Gregor &lt;<a href=mailto:[email protected]>[email protected]</a>&gt;
@@ -5399,13 +5399,15 @@
 
   <ol>
     <li>If <var title="">override</var> is a boolean, and <code title=queryCommandState()><a href=#querycommandstate()>queryCommandState(<var title="">command</var>)</a></code>
-    returns something different from <var title="">override</var>, call <code title=execCommand()><a href=#execcommand()>execCommand(<var title="">command</var>)</a></code>.
+    returns something different from <var title="">override</var>, take the
+    <a href=#action>action</a> for <var title="">command</var>, with <var title="">value</var> equal to
+    the empty string.
 
     <li>Otherwise, if <var title="">override</var> is a string, and <var title="">command</var>
     is neither "createLink" nor "fontSize", and <code title=queryCommandValue()><a href=#querycommandvalue()>queryCommandValue(<var title="">command</var>)</a></code>
     returns something not <a href=#equivalent-values title="equivalent values">equivalent</a> to
-    <var title="">override</var>, call <code title=execCommand()><a href=#execcommand()>execCommand(<var title="">command</var>, false,
-    <var title="">override</var>)</a></code>.
+    <var title="">override</var>, take the <a href=#action>action</a> for <var title="">command</var>,
+    with <var title="">value</var> equal to <var title="">override</var>.
 
     <li>
     <p class=comments>This special case is needed because <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=14067">createLink has no
@@ -5416,8 +5418,8 @@
     "createLink" that is not equal to <var title="">override</var>, or there is no
     <a href=#value-override>value override</a> for "createLink" and <var title="">node</var>'s
     <a href=#effective-command-value>effective command value</a> for "createLink" is not equal to
-    <var title="">override</var>: call <code title=execCommand()><a href=#execcommand()>execCommand("createLink", false,
-    <var title="">override</var>)</a></code>.
+    <var title="">override</var>: take the <var title="">action</var> for "createLink", with
+    <var title="">value</var> equal to <var title="">override</var>.
 
     <li>
     <p class=comments>The override will be some CSS value, so we have to
@@ -5434,13 +5436,14 @@
       <li>Convert <var title="">override</var> to an integer number of pixels, and set
       <var title="">override</var> to the <a href=#legacy-font-size-for>legacy font size for</a> the result.
 
-      <li>Call <code title=execCommand()><a href=#execcommand()>execCommand("fontSize", false, <var title="">override</var>)</a></code>.
+      <li>Take the <a href=#action>action</a> for "fontSize", with <var title="">value</var>
+      equal to <var title="">override</var>.
     </ol>
 
     <li>Otherwise, continue this loop from the beginning.
 
     <li>
-    <p class=comments>If we called <code title="">execCommand()</code>, we need to reset
+    <p class=comments>If we took the action for a command, we need to reset
     <var title="">node</var>, because it might have changed.  For instance, if the
     selection was <code title="">foo[bar]baz</code>, the text node could have been split so
     that the first part is now outside the active range.
@@ -7764,8 +7767,8 @@
   offset</var>) and <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range-end title=concept-range-end>end</a> (<var title="">node</var>, <var title="">end offset</var>), and
   set 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>'s <a href=#concept-selection title=concept-selection>selection</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> to it.
 
-  <li>Call <code title=execCommand()><a href=#execcommand()>execCommand("createLink", false, <var title="">href</var>)</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>.
+  <li>Take the <a href=#action>action</a> for "createLink", with <var title="">value</var>
+  equal to <var title="">href</var>.
 
   <li>Set 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>'s <a href=#concept-selection title=concept-selection>selection</a>'s <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-range title=concept-range>range</a> to <var title="">original
   range</var>.
--- a/implementation.js	Mon Mar 12 13:35:46 2012 -0600
+++ b/implementation.js	Mon Mar 12 13:35:59 2012 -0600
@@ -4405,28 +4405,28 @@
 			var override = overrides[i][1];
 
 			// "If override is a boolean, and queryCommandState(command)
-			// returns something different from override, call
-			// execCommand(command)."
+			// returns something different from override, take the action for
+			// command, with value equal to the empty string."
 			if (typeof override == "boolean"
 			&& myQueryCommandState(command) != override) {
-				myExecCommand(command);
+				commands[command].action("");
 
 			// "Otherwise, if override is a string, and command is neither
 			// "createLink" nor "fontSize", and queryCommandValue(command)
-			// returns something not equivalent to override, call
-			// execCommand(command, false, override)."
+			// returns something not equivalent to override, take the action
+			// for command, with value equal to override."
 			} else if (typeof override == "string"
 			&& command != "createlink"
 			&& command != "fontsize"
 			&& !areEquivalentValues(command, myQueryCommandValue(command), override)) {
-				myExecCommand(command, false, override);
+				commands[command].action(override);
 
 			// "Otherwise, if override is a string; and command is
 			// "createLink"; and either there is a value override for
 			// "createLink" that is not equal to override, or there is no value
 			// override for "createLink" and node's effective command value for
-			// "createLink" is not equal to override: call
-			// execCommand("createLink", false, override)."
+			// "createLink" is not equal to override: take the action for
+			// "createLink", with value equal to override."
 			} else if (typeof override == "string"
 			&& command == "createlink"
 			&& (
@@ -4438,7 +4438,7 @@
 					&& getEffectiveCommandValue(node, "createlink") !== override
 				)
 			)) {
-				myExecCommand("createlink", false, override);
+				commands.createlink.action(override);
 
 			// "Otherwise, if override is a string; and command is "fontSize";
 			// and either there is a value override for "fontSize" that is not
@@ -4460,8 +4460,9 @@
 				// override to the legacy font size for the result."
 				override = getLegacyFontSize(override);
 
-				// "Call execCommand("fontSize", false, override)."
-				myExecCommand("fontsize", false, override);
+				// "Take the action for "fontSize", with value equal to
+				// override."
+				commands.fontsize.action(override);
 
 			// "Otherwise, continue this loop from the beginning."
 			} else {
@@ -6146,8 +6147,8 @@
 	getSelection().addRange(newRange);
 	globalRange = newRange;
 
-	// "Call execCommand("createLink", false, href) on the context object."
-	myExecCommand("createLink", false, href);
+	// "Take the action for "createLink", with value equal to href."
+	commands.createlink.action(href);
 
 	// "Set the context object's selection's range to original range."
 	getSelection().removeAllRanges();
--- a/source.html	Mon Mar 12 13:35:46 2012 -0600
+++ b/source.html	Mon Mar 12 13:35:59 2012 -0600
@@ -5449,16 +5449,16 @@
   <ol>
     <li>If <var>override</var> is a boolean, and <code
     title=queryCommandState()>queryCommandState(<var>command</var>)</code>
-    returns something different from <var>override</var>, call <code
-    title=execCommand()>execCommand(<var>command</var>)</code>.
+    returns something different from <var>override</var>, take the
+    <span>action</span> for <var>command</var>, with <var>value</var> equal to
+    the empty string.
 
     <li>Otherwise, if <var>override</var> is a string, and <var>command</var>
     is neither "createLink" nor "fontSize", and <code
     title=queryCommandValue()>queryCommandValue(<var>command</var>)</code>
     returns something not <span title="equivalent values">equivalent</span> to
-    <var>override</var>, call <code
-    title=execCommand()>execCommand(<var>command</var>, false,
-    <var>override</var>)</code>.
+    <var>override</var>, take the <span>action</span> for <var>command</var>,
+    with <var>value</var> equal to <var>override</var>.
 
     <li>
     <p class=comments>This special case is needed because <a
@@ -5470,8 +5470,8 @@
     "createLink" that is not equal to <var>override</var>, or there is no
     <span>value override</span> for "createLink" and <var>node</var>'s
     <span>effective command value</span> for "createLink" is not equal to
-    <var>override</var>: call [[execcommand|"createLink", false,
-    <var>override</var>]].
+    <var>override</var>: take the <var>action</var> for "createLink", with
+    <var>value</var> equal to <var>override</var>.
 
     <li>
     <p class=comments>The override will be some CSS value, so we have to
@@ -5488,13 +5488,14 @@
       <li>Convert <var>override</var> to an integer number of pixels, and set
       <var>override</var> to the <span>legacy font size for</span> the result.
 
-      <li>Call [[execcommand|"fontSize", false, <var>override</var>]].
+      <li>Take the <span>action</span> for "fontSize", with <var>value</var>
+      equal to <var>override</var>.
     </ol>
 
     <li>Otherwise, continue this loop from the beginning.
 
     <li>
-    <p class=comments>If we called {{code|execCommand()}}, we need to reset
+    <p class=comments>If we took the action for a command, we need to reset
     <var>node</var>, because it might have changed.  For instance, if the
     selection was {{code|foo[bar]baz}}, the text node could have been split so
     that the first part is now outside the active range.
@@ -7852,8 +7853,8 @@
   offset</var>) and [[rangeend]] (<var>node</var>, <var>end offset</var>), and
   set the [[contextobject]]'s [[selection]]'s [[range]] to it.
 
-  <li>Call [[execcommand|"createLink", false, <var>href</var>]] on the
-  [[contextobject]].
+  <li>Take the <span>action</span> for "createLink", with <var>value</var>
+  equal to <var>href</var>.
 
   <li>Set the [[contextobject]]'s [[selection]]'s [[range]] to <var>original
   range</var>.