Browse Source

Minor changes

- after a browser refresh the last executed undo is now selected in the
Sidebar.History
Daniel 9 years ago
parent
commit
d71c0e2895
3 changed files with 9 additions and 11 deletions
  1. 0 1
      editor/js/Cmd.js
  2. 8 9
      editor/js/History.js
  3. 1 1
      test/unit/editor/TestSerialization.js

+ 0 - 1
editor/js/Cmd.js

@@ -36,6 +36,5 @@ Cmd.prototype.fromJSON = function ( json ) {
 	this.type = json.type;
 	this.id = json.id;
 	this.name = json.name;
-	this.json = json;
 
 };

+ 8 - 9
editor/js/History.js

@@ -70,10 +70,10 @@ History.prototype = {
 			cmd.id = ++this.idCounter;
 
 		}
-		cmd.name = optionalName !== undefined ? optionalName : cmd.name;
+		cmd.name = ( optionalName !== undefined ) ? optionalName : cmd.name;
 		cmd.execute();
 		cmd.inMemory = true;
-		cmd.json = cmd.toJSON();	// serialize cmd immediately after execution
+		cmd.json = cmd.toJSON();	// serialize the cmd immediately after execution and append the json to the cmd
 
 		this.lastCmdTime = new Date();
 
@@ -164,8 +164,7 @@ History.prototype = {
 
 		for ( var i = 0 ; i < this.undos.length; i++ ) {
 
-			var cmd = this.undos[ i ];
-			undos.push( cmd.json );
+			undos.push( this.undos[ i ].json );
 
 		}
 
@@ -177,8 +176,7 @@ History.prototype = {
 
 		for ( var i = 0 ; i < this.redos.length; i++ ) {
 
-			var cmd = this.redos[ i ];
-			redos.push( cmd.json );
+			redos.push( this.redos[ i ].json );
 
 		}
 
@@ -198,7 +196,7 @@ History.prototype = {
 			var cmd = new window[ cmdJSON.type ]();	// creates a new object of type "json.type"
 			cmd.json = cmdJSON;
 			this.undos.push( cmd );
-			this.idCounter = cmdJSON.id > this.idCounter ? cmdJSON.id : this.idCounter; // set last used idCounter
+			this.idCounter = ( cmdJSON.id > this.idCounter ) ? cmdJSON.id : this.idCounter; // set last used idCounter
 
 		}
 
@@ -208,11 +206,12 @@ History.prototype = {
 			var cmd = new window[ cmdJSON.type ]();	// creates a new object of type "json.type"
 			cmd.json = cmdJSON;
 			this.redos.push( cmd );
-			this.idCounter = cmdJSON.id > this.idCounter ? cmdJSON.id : this.idCounter; // set last used idCounter
+			this.idCounter = ( cmdJSON.id > this.idCounter ) ? cmdJSON.id : this.idCounter; // set last used idCounter
 
 		}
 
-		this.editor.signals.historyChanged.dispatch();
+		// Select the last executed undo-command
+		this.editor.signals.historyChanged.dispatch( this.undos[ this.undos.length - 1 ] );
 
 	},
 

+ 1 - 1
test/unit/editor/TestSerialization.js

@@ -1,6 +1,6 @@
 module( "Serialization" );
 
-test( "Test Serialization (simple)", function() {
+test( "Test Serialization", function() {
 
 	// setup
 	var editor = new Editor();