Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit e278e1b

Browse files
Merge pull request #58 from CapnRat/ui/make-enter-work
Accept Enter/Return as confirm keys in authentication flow. Fixes #59
2 parents 2a9a212 + ef76c76 commit e278e1b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using UnityEngine;
33
using UnityEditor;
44

@@ -26,6 +26,7 @@ class AuthenticationView : Subview
2626
[NonSerialized] private bool need2fa;
2727
[NonSerialized] private bool busy;
2828
[NonSerialized] private string message;
29+
[NonSerialized] private bool enterPressed;
2930

3031
[NonSerialized] private AuthenticationService authenticationService;
3132
private AuthenticationService AuthenticationService
@@ -73,6 +74,8 @@ public override void OnHide()
7374

7475
public override void OnGUI()
7576
{
77+
HandleEnterPressed();
78+
7679
scroll = GUILayout.BeginScrollView(scroll);
7780
{
7881
Rect authHeader = EditorGUILayout.BeginHorizontal(Styles.AuthHeaderBoxStyle);
@@ -116,6 +119,16 @@ public override void OnGUI()
116119
GUILayout.EndScrollView();
117120
}
118121

122+
private void HandleEnterPressed()
123+
{
124+
if (Event.current.type != EventType.KeyDown)
125+
return;
126+
127+
enterPressed = Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter;
128+
if (enterPressed)
129+
Event.current.Use();
130+
}
131+
119132
private void OnGUILogin()
120133
{
121134
GUILayout.Space(3);
@@ -142,7 +155,7 @@ private void OnGUILogin()
142155
if (busy) GUI.enabled = false;
143156
GUILayout.BeginHorizontal();
144157
GUILayout.FlexibleSpace();
145-
if (GUILayout.Button(loginButton))
158+
if (GUILayout.Button(loginButton) || (GUI.enabled && enterPressed))
146159
{
147160
GUI.FocusControl(null);
148161
busy = true;
@@ -185,7 +198,7 @@ private void OnGUI2FA()
185198

186199
GUILayout.Space(Styles.BaseSpacing);
187200

188-
if (GUILayout.Button(twofaButton))
201+
if (GUILayout.Button(twofaButton) || (GUI.enabled && enterPressed))
189202
{
190203
GUI.FocusControl(null);
191204
busy = true;

0 commit comments

Comments
 (0)