Make save/restore state work better
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Thu, 21 Jul 2011 15:23:15 -0600
changeset 438 ee56099364e6
parent 437 755a8d43ea86
child 439 d521738e127f
Make save/restore state work better

Only save the overrides. This avoids problems when changing one thing
also changes another, like adding a link that also changes color.
editcommands.html
implementation.js
source.html
--- a/editcommands.html	Thu Jul 21 15:03:51 2011 -0600
+++ b/editcommands.html	Thu Jul 21 15:23:15 2011 -0600
@@ -38,7 +38,7 @@
 <body class=draft>
 <div class=head id=head>
 <h1>HTML Editing Commands</h1>
-<h2 class="no-num no-toc" id=work-in-progress-&mdash;-last-update-20-july-2011>Work in Progress &mdash; Last Update 20 July 2011</h2>
+<h2 class="no-num no-toc" id=work-in-progress-&mdash;-last-update-21-july-2011>Work in Progress &mdash; Last Update 21 July 2011</h2>
 <dl>
  <dt>Editor
  <dd>Aryeh Gregor &lt;<a href=mailto:ayg@aryeh.name>ayg@aryeh.name</a>&gt;
@@ -985,14 +985,16 @@
   <li>Let <var title="">states</var> be a dictionary mapping <a href=#command title=command>commands</a> to booleans, initially empty.
 
   <li>For each <a href=#command-with-insertion-affecting-state>command with insertion-affecting state</a>
-  <var title="">command</var>, in order, add an entry to <var title="">states</var> mapping
-  <var title="">command</var> to the result of <code title=queryCommandState()><a href=#querycommandstate()>queryCommandState(<var title="">command</var>)</a></code>.
+  <var title="">command</var>, in order, if there is a <a href=#state-override>state override</a> for
+  <var title="">command</var>, add an entry to <var title="">states</var> mapping
+  <var title="">command</var> to its <a href=#state-override>state override</a>.
 
   <li>Let <var title="">values</var> be a dictionary mapping <a href=#command title=command>commands</a> to strings, initially empty.
 
   <li>For each <a href=#command-with-insertion-affecting-value>command with insertion-affecting value</a>
-  <var title="">command</var>, in order, add an entry to <var title="">values</var> mapping
-  <var title="">command</var> to the result of <code title=queryCommandValue()><a href=#querycommandvalue()>queryCommandValue(<var title="">command</var>)</a></code>.
+  <var title="">command</var>, in order, if there is a <a href=#value-override>value override</a> for
+  <var title="">command</var>, add an entry to <var title="">values</var> mapping
+  <var title="">command</var> to its <a href=#value-override>value override</a>.
 
   <li>Return (<var title="">states</var>, <var title="">values</var>).
 </ol>
--- a/implementation.js	Thu Jul 21 15:03:51 2011 -0600
+++ b/implementation.js	Thu Jul 21 15:23:15 2011 -0600
@@ -1251,22 +1251,26 @@
 	// empty."
 	var states = {};
 
-	// "For each command with insertion-affecting state command, in order, add
-	// an entry to states mapping command to the result of
-	// queryCommandState(command)."
+	// "For each command with insertion-affecting state command, in order, if
+	// there is a state override for command, add an entry to states mapping
+	// command to its state override."
 	commandsWithInsertionAffectingState.forEach(function(command) {
-		states[command] = myQueryCommandState(command);
+		if (getStateOverride(command) !== undefined) {
+			states[command] = getStateOverride(command);
+		}
 	});
 
 	// "Let values be a dictionary mapping commands to strings, initially
 	// empty."
 	var values = {};
 
-	// "For each command with insertion-affecting value command, in order, add
-	// an entry to values mapping command to the result of
-	// queryCommandValue(command)."
+	// "For each command with insertion-affecting value command, in order, if
+	// there is a value override for command, add an entry to values mapping
+	// command to its value override."
 	commandsWithInsertionAffectingValue.forEach(function(command) {
-		values[command] = myQueryCommandValue(command);
+		if (getValueOverride(command) !== undefined) {
+			values[command] = getValueOverride(command);
+		}
 	});
 
 	// "Return (states, values)."
--- a/source.html	Thu Jul 21 15:03:51 2011 -0600
+++ b/source.html	Thu Jul 21 15:23:15 2011 -0600
@@ -940,17 +940,17 @@
   title=command>commands</span> to booleans, initially empty.
 
   <li>For each <span>command with insertion-affecting state</span>
-  <var>command</var>, in order, add an entry to <var>states</var> mapping
-  <var>command</var> to the result of <code
-  title=queryCommandState()>queryCommandState(<var>command</var>)</code>.
+  <var>command</var>, in order, if there is a <span>state override</span> for
+  <var>command</var>, add an entry to <var>states</var> mapping
+  <var>command</var> to its <span>state override</span>.
 
   <li>Let <var>values</var> be a dictionary mapping <span
   title=command>commands</span> to strings, initially empty.
 
   <li>For each <span>command with insertion-affecting value</span>
-  <var>command</var>, in order, add an entry to <var>values</var> mapping
-  <var>command</var> to the result of <code
-  title=queryCommandValue()>queryCommandValue(<var>command</var>)</code>.
+  <var>command</var>, in order, if there is a <span>value override</span> for
+  <var>command</var>, add an entry to <var>values</var> mapping
+  <var>command</var> to its <span>value override</span>.
 
   <li>Return (<var>states</var>, <var>values</var>).
 </ol>