From 2c3299db59c89f2ebf1b084f829938fff011acdd Mon Sep 17 00:00:00 2001 From: Shawn White Date: Thu, 29 Jun 2017 01:11:56 +0200 Subject: [PATCH] Accept Enter/Return as confirm keys in authentication flow. --- .../GitHub.Unity/UI/AuthenticationView.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs index 776de321f..546a402d9 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs @@ -1,4 +1,4 @@ -using System; +using System; using UnityEngine; using UnityEditor; @@ -26,6 +26,7 @@ class AuthenticationView : Subview [NonSerialized] private bool need2fa; [NonSerialized] private bool busy; [NonSerialized] private string message; + [NonSerialized] private bool enterPressed; [NonSerialized] private AuthenticationService authenticationService; private AuthenticationService AuthenticationService @@ -73,6 +74,8 @@ public override void OnHide() public override void OnGUI() { + HandleEnterPressed(); + scroll = GUILayout.BeginScrollView(scroll); { Rect authHeader = EditorGUILayout.BeginHorizontal(Styles.AuthHeaderBoxStyle); @@ -116,6 +119,16 @@ public override void OnGUI() GUILayout.EndScrollView(); } + private void HandleEnterPressed() + { + if (Event.current.type != EventType.KeyDown) + return; + + enterPressed = Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter; + if (enterPressed) + Event.current.Use(); + } + private void OnGUILogin() { GUILayout.Space(3); @@ -142,7 +155,7 @@ private void OnGUILogin() if (busy) GUI.enabled = false; GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); - if (GUILayout.Button(loginButton)) + if (GUILayout.Button(loginButton) || (GUI.enabled && enterPressed)) { GUI.FocusControl(null); busy = true; @@ -185,7 +198,7 @@ private void OnGUI2FA() GUILayout.Space(Styles.BaseSpacing); - if (GUILayout.Button(twofaButton)) + if (GUILayout.Button(twofaButton) || (GUI.enabled && enterPressed)) { GUI.FocusControl(null); busy = true;