瀏覽代碼

Undo/Redo fixes

Tyler Lindberg 7 年之前
父節點
當前提交
d47644c2db
共有 1 個文件被更改,包括 16 次插入14 次删除
  1. 16 14
      editor/js/Sidebar.Controls.js

+ 16 - 14
editor/js/Sidebar.Controls.js

@@ -11,7 +11,7 @@ Sidebar.Controls = function ( editor ) {
 
 	var isValidKeyBinding = function ( key ) {
 
-		return key.match( /^[A-Za-z0-9]$/i );
+		return key.match( /^[A-Za-z0-9]$/i ); // Can't use z currently due to undo/redo
 
 	};
 
@@ -27,7 +27,7 @@ Sidebar.Controls = function ( editor ) {
 		'scale'
 	];
 
-	for ( var i = 0; i < controlNames.length; i++ ) {
+	for ( var i = 0; i < controlNames.length; i ++ ) {
 
 		let name = controlNames[ i ];
 		let configName = 'controls/' + name;
@@ -35,7 +35,7 @@ Sidebar.Controls = function ( editor ) {
 
 		let controlInput = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
 
-			if( isValidKeyBinding( controlInput.getValue() ) ) {
+			if ( isValidKeyBinding( controlInput.getValue() ) ) {
 
 				config.setKey( configName, controlInput.getValue()[ 0 ] );
 
@@ -54,7 +54,7 @@ Sidebar.Controls = function ( editor ) {
 		// to contain the key binding stored in config
 		controlInput.dom.addEventListener( 'blur', function () {
 
-			if( ! isValidKeyBinding( controlInput.getValue() ) ) {
+			if ( ! isValidKeyBinding( controlInput.getValue() ) ) {
 
 				controlInput.setValue( config.getKey( configName ) );
 
@@ -65,7 +65,7 @@ Sidebar.Controls = function ( editor ) {
 		// If a valid key binding character is entered, blur the input field
 		controlInput.dom.addEventListener( 'keyup', function ( event ) {
 
-			if( isValidKeyBinding( event.key ) ) {
+			if ( isValidKeyBinding( event.key ) ) {
 
 				controlInput.dom.blur();
 
@@ -73,7 +73,7 @@ Sidebar.Controls = function ( editor ) {
 
 		} );
 
-		if( config.getKey( configName ) !== undefined ) {
+		if ( config.getKey( configName ) !== undefined ) {
 
 			controlInput.setValue( config.getKey( configName ) );
 
@@ -105,24 +105,26 @@ Sidebar.Controls = function ( editor ) {
 
 				break;
 
-			case 'z': // Register Ctrl/Command-Z for Undo
+			case 'z': // Register Ctrl/Command-Z for Undo and Ctrl/Command-Shift-Z for Redo
+			case 'Z': // Safari and Firefox register lowercase z when Ctrl-Shift-Z is pressed
 
 				if ( IS_MAC ? event.metaKey : event.ctrlKey ) {
 
-					editor.undo();
+					if ( event.shiftKey ) {
 
-				}
-
-				break;
+						editor.redo();
 
-			case 'Z': // Register Ctrl/Command-Shift-Z for Redo
+					}					else {
 
-				if ( IS_MAC ? event.metaKey : event.ctrlKey ) {
+						event.preventDefault(); // Prevent Safari reopen last tab
+						editor.undo();
 
-					editor.redo();
+					}
 
 				}
 
+				break;
+
 			case editor.config.getKey( 'controls/translate' ): // Translation transform mode
 
 				editor.signals.transformModeChanged.dispatch( 'translate' );