diff --git a/Scripts/Editor/RenamePopup.cs b/Scripts/Editor/RenamePopup.cs index 5429270a..a43837f0 100644 --- a/Scripts/Editor/RenamePopup.cs +++ b/Scripts/Editor/RenamePopup.cs @@ -1,9 +1,11 @@ -using UnityEditor; +using UnityEditor; using UnityEngine; namespace XNodeEditor { /// Utility for renaming assets public class RenamePopup : EditorWindow { + private const string inputControlName = "nameInput"; + public static RenamePopup current { get; private set; } public Object target; public string input; @@ -19,7 +21,6 @@ public static RenamePopup Show(Object target, float width = 200) { window.input = target.name; window.minSize = new Vector2(100, 44); window.position = new Rect(0, 0, width, 44); - GUI.FocusControl("ClearAllFocus"); window.UpdatePositionToMouse(); return window; } @@ -43,7 +44,9 @@ private void OnGUI() { UpdatePositionToMouse(); firstFrame = false; } + GUI.SetNextControlName(inputControlName); input = EditorGUILayout.TextField(input); + EditorGUI.FocusTextInControl(inputControlName); Event e = Event.current; // If input is empty, revert name to default instead if (input == null || input.Trim() == "") { @@ -67,6 +70,14 @@ private void OnGUI() { target.TriggerOnValidate(); } } + + if (e.isKey && e.keyCode == KeyCode.Escape) { + Close(); + } + } + + private void OnDestroy() { + EditorGUIUtility.editingTextField = false; } } } \ No newline at end of file