Przeglądaj źródła

Made it more clear when a command will be updated in history.js

Issue #39

Fixed an issue with the codemirror-undo/redo-history, where extra steps
were added because of „codemirror.setValue()“
Daniel 9 lat temu
rodzic
commit
fb3a2812d9

+ 12 - 0
editor/docs/Implementing additional commands for undo-redo.md

@@ -108,6 +108,18 @@ update: function ( cmd ) {
 
 ```
 
+#### List of updatable commands
+
+- CmdSetColor
+- CmdSetGeometry
+- CmdSetMaterialColor
+- CmdSetMaterialValue
+- CmdSetPosition
+- CmdSetRotation
+- CmdSetScale
+- CmdSetValue
+- CmdSetScriptValue
+
 The idea behind 'updatable commands' is that two commands of the same type which occur
 within a short period of time should be merged into one.
 **For example:** Dragging with your mouse over the x-position field in the sidebar

+ 10 - 9
editor/js/History.js

@@ -38,29 +38,30 @@ History.prototype = {
 		var lastCmd = this.undos[ this.undos.length - 1 ];
 		var timeDifference = new Date().getTime() - this.lastCmdTime.getTime();
 
-		var isScriptCmd = lastCmd &&
+		var isUpdatableCmd = lastCmd &&
 			lastCmd.updatable &&
 			cmd.updatable &&
-			lastCmd.script !== undefined &&
 			lastCmd.object === cmd.object &&
 			lastCmd.type === cmd.type &&
 			lastCmd.script === cmd.script &&
 			lastCmd.attributeName === cmd.attributeName;
 
-		var isUpdatableCmd = lastCmd &&
-			lastCmd.updatable &&
-			cmd.updatable &&
-			lastCmd.object === cmd.object &&
-			lastCmd.type === cmd.type &&
-			timeDifference < 500;
+		if ( isUpdatableCmd && cmd.type === "CmdSetScriptValue" ) {
 
-		if ( isScriptCmd || isUpdatableCmd ) {
+			// When the cmd.type is "CmdSetScriptValue" the timeDifference is ignored
+
+			lastCmd.update( cmd );
+			cmd = lastCmd;
+
+		} else if ( isUpdatableCmd && timeDifference < 500 ) {
 
 			lastCmd.update( cmd );
 			cmd = lastCmd;
 
 		} else {
 
+			// the command is not updatable and is added as a new part of the history
+
 			this.undos.push( cmd );
 			cmd.editor = this.editor;
 			cmd.id = ++this.idCounter;

+ 4 - 0
editor/js/Script.js

@@ -424,6 +424,9 @@ var Script = function ( editor ) {
 
 		if ( currentScript !== script ) return;
 
+		// copying the codemirror history because "codemirror.setValue(...)" alters its history
+
+		var history = codemirror.getHistory();
 		title.setValue( object.name + ' / ' + script.name );
 		codemirror.setValue( script.source );
 
@@ -432,6 +435,7 @@ var Script = function ( editor ) {
 			codemirror.setCursor( cursorPosition );
 
 		}
+		codemirror.setHistory( history ); // setting the history to previous state
 
 	} );