Browse Source

Editor: Fixed autoscrolling

Mugen87 8 years ago
parent
commit
48d989d585
2 changed files with 11 additions and 5 deletions
  1. 3 2
      editor/js/Script.js
  2. 8 3
      editor/js/commands/SetScriptValueCommand.js

+ 3 - 2
editor/js/Script.js

@@ -84,7 +84,7 @@ var Script = function ( editor ) {
 
 
 				if ( value !== currentScript.source ) {
 				if ( value !== currentScript.source ) {
 
 
-					editor.execute( new SetScriptValueCommand( currentObject, currentScript, 'source', value, codemirror.getCursor() ) );
+					editor.execute( new SetScriptValueCommand( currentObject, currentScript, 'source', value, codemirror.getCursor(), codemirror.getScrollInfo() ) );
 
 
 				}
 				}
 				return;
 				return;
@@ -422,7 +422,7 @@ var Script = function ( editor ) {
 
 
 	} );
 	} );
 
 
-	signals.refreshScriptEditor.add( function ( object, script, cursorPosition ) {
+	signals.refreshScriptEditor.add( function ( object, script, cursorPosition, scrollInfo ) {
 
 
 		if ( currentScript !== script ) return;
 		if ( currentScript !== script ) return;
 
 
@@ -435,6 +435,7 @@ var Script = function ( editor ) {
 		if ( cursorPosition !== undefined ) {
 		if ( cursorPosition !== undefined ) {
 
 
 			codemirror.setCursor( cursorPosition );
 			codemirror.setCursor( cursorPosition );
+			codemirror.scrollTo( scrollInfo.left, scrollInfo.top );
 
 
 		}
 		}
 		codemirror.setHistory( history ); // setting the history to previous state
 		codemirror.setHistory( history ); // setting the history to previous state

+ 8 - 3
editor/js/commands/SetScriptValueCommand.js

@@ -9,10 +9,11 @@
  * @param attributeName string
  * @param attributeName string
  * @param newValue string, object
  * @param newValue string, object
  * @param cursorPosition javascript object with format {line: 2, ch: 3}
  * @param cursorPosition javascript object with format {line: 2, ch: 3}
+ * @param scrollInfo javascript object with values {left, top, width, height, clientWidth, clientHeight}
  * @constructor
  * @constructor
  */
  */
 
 
-var SetScriptValueCommand = function ( object, script, attributeName, newValue, cursorPosition ) {
+var SetScriptValueCommand = function ( object, script, attributeName, newValue, cursorPosition, scrollInfo ) {
 
 
 	Command.call( this );
 	Command.call( this );
 
 
@@ -27,6 +28,7 @@ var SetScriptValueCommand = function ( object, script, attributeName, newValue,
 	this.oldValue = ( script !== undefined ) ? script[ this.attributeName ] : undefined;
 	this.oldValue = ( script !== undefined ) ? script[ this.attributeName ] : undefined;
 	this.newValue = newValue;
 	this.newValue = newValue;
 	this.cursorPosition = cursorPosition;
 	this.cursorPosition = cursorPosition;
+	this.scrollInfo = scrollInfo;
 
 
 };
 };
 
 
@@ -37,7 +39,7 @@ SetScriptValueCommand.prototype = {
 		this.script[ this.attributeName ] = this.newValue;
 		this.script[ this.attributeName ] = this.newValue;
 
 
 		this.editor.signals.scriptChanged.dispatch();
 		this.editor.signals.scriptChanged.dispatch();
-		this.editor.signals.refreshScriptEditor.dispatch( this.object, this.script, this.cursorPosition );
+		this.editor.signals.refreshScriptEditor.dispatch( this.object, this.script, this.cursorPosition, this.scrollInfo );
 
 
 	},
 	},
 
 
@@ -46,13 +48,14 @@ SetScriptValueCommand.prototype = {
 		this.script[ this.attributeName ] = this.oldValue;
 		this.script[ this.attributeName ] = this.oldValue;
 
 
 		this.editor.signals.scriptChanged.dispatch();
 		this.editor.signals.scriptChanged.dispatch();
-		this.editor.signals.refreshScriptEditor.dispatch( this.object, this.script, this.cursorPosition );
+		this.editor.signals.refreshScriptEditor.dispatch( this.object, this.script, this.cursorPosition, this.scrollInfo );
 
 
 	},
 	},
 
 
 	update: function ( cmd ) {
 	update: function ( cmd ) {
 
 
 		this.cursorPosition = cmd.cursorPosition;
 		this.cursorPosition = cmd.cursorPosition;
+		this.scrollInfo = cmd.scrollInfo;
 		this.newValue = cmd.newValue;
 		this.newValue = cmd.newValue;
 
 
 	},
 	},
@@ -67,6 +70,7 @@ SetScriptValueCommand.prototype = {
 		output.oldValue = this.oldValue;
 		output.oldValue = this.oldValue;
 		output.newValue = this.newValue;
 		output.newValue = this.newValue;
 		output.cursorPosition = this.cursorPosition;
 		output.cursorPosition = this.cursorPosition;
+		output.scrollInfo = this.scrollInfo;
 
 
 		return output;
 		return output;
 
 
@@ -82,6 +86,7 @@ SetScriptValueCommand.prototype = {
 		this.object = this.editor.objectByUuid( json.objectUuid );
 		this.object = this.editor.objectByUuid( json.objectUuid );
 		this.script = this.editor.scripts[ json.objectUuid ][ json.index ];
 		this.script = this.editor.scripts[ json.objectUuid ][ json.index ];
 		this.cursorPosition = json.cursorPosition;
 		this.cursorPosition = json.cursorPosition;
+		this.scrollInfo = json.scrollInfo;
 
 
 	}
 	}