Skip to content

Commit a9ddfdf

Browse files
authored
Workaround issue #1293 by avoiding setting textbox focus on Mac (#1314)
There appears to be an issue with setting focus with empty textboxes on macOS. Let's put in a quick workaround for now to avoid the crash that happens otherwise. On Mac, do not attempt to set the focus to a text box. Workaround #1293
2 parents 8e3867f + 6c12ea9 commit a9ddfdf

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

src/shared/Atlassian.Bitbucket/UI/Views/CredentialsView.axaml.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Atlassian.Bitbucket.UI.ViewModels;
22
using Avalonia.Controls;
33
using Avalonia.Markup.Xaml;
4+
using GitCredentialManager;
45
using GitCredentialManager.UI.Controls;
56

67
namespace Atlassian.Bitbucket.UI.Views
@@ -44,11 +45,15 @@ public void SetFocus()
4445
_tabControl.SelectedIndex = 1;
4546
if (string.IsNullOrWhiteSpace(vm.UserName))
4647
{
47-
_userNameTextBox.Focus();
48+
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
49+
if (!PlatformUtils.IsMacOS())
50+
_userNameTextBox.Focus();
4851
}
4952
else
5053
{
51-
_passwordTextBox.Focus();
54+
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
55+
if (!PlatformUtils.IsMacOS())
56+
_passwordTextBox.Focus();
5257
}
5358
}
5459
}

src/shared/Core/UI/Views/CredentialsView.axaml.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ public void SetFocus()
3232

3333
if (string.IsNullOrWhiteSpace(vm.UserName))
3434
{
35-
_userNameTextBox.Focus();
35+
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
36+
if (!PlatformUtils.IsMacOS())
37+
_userNameTextBox.Focus();
3638
}
3739
else
3840
{
39-
_passwordTextBox.Focus();
41+
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
42+
if (!PlatformUtils.IsMacOS())
43+
_passwordTextBox.Focus();
4044
}
4145
}
4246
}

src/shared/GitHub/UI/Controls/SixDigitInput.axaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Avalonia.Input.Platform;
99
using Avalonia.Interactivity;
1010
using Avalonia.Markup.Xaml;
11+
using GitCredentialManager;
1112
using GitCredentialManager.UI.Controls;
1213

1314
namespace GitHub.UI.Controls
@@ -86,7 +87,9 @@ private void SetTextBoxes(string text)
8687

8788
public void SetFocus()
8889
{
89-
KeyboardDevice.Instance.SetFocusedElement(_textBoxes[0], NavigationMethod.Tab, KeyModifiers.None);
90+
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
91+
if (!PlatformUtils.IsMacOS())
92+
KeyboardDevice.Instance.SetFocusedElement(_textBoxes[0], NavigationMethod.Tab, KeyModifiers.None);
9093
}
9194

9295
private void SetUpTextBox(TextBox textBox)

src/shared/GitHub/UI/Views/CredentialsView.axaml.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Avalonia.Controls;
22
using Avalonia.Markup.Xaml;
3+
using GitCredentialManager;
34
using GitHub.UI.ViewModels;
45
using GitCredentialManager.UI.Controls;
56

@@ -53,19 +54,25 @@ public void SetFocus()
5354
else if (vm.ShowTokenLogin)
5455
{
5556
_tabControl.SelectedIndex = 1;
56-
_tokenTextBox.Focus();
57+
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
58+
if (!PlatformUtils.IsMacOS())
59+
_tokenTextBox.Focus();
5760

5861
}
5962
else if (vm.ShowBasicLogin)
6063
{
6164
_tabControl.SelectedIndex = 2;
6265
if (string.IsNullOrWhiteSpace(vm.UserName))
6366
{
64-
_userNameTextBox.Focus();
67+
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
68+
if (!PlatformUtils.IsMacOS())
69+
_userNameTextBox.Focus();
6570
}
6671
else
6772
{
68-
_passwordTextBox.Focus();
73+
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
74+
if (!PlatformUtils.IsMacOS())
75+
_passwordTextBox.Focus();
6976
}
7077
}
7178
}

src/shared/GitHub/UI/Views/TwoFactorView.axaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Avalonia.Controls;
22
using Avalonia.Markup.Xaml;
3+
using GitCredentialManager;
34
using GitHub.UI.Controls;
45
using GitCredentialManager.UI.Controls;
56

@@ -23,7 +24,9 @@ private void InitializeComponent()
2324

2425
public void SetFocus()
2526
{
26-
_codeInput.SetFocus();
27+
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
28+
if (!PlatformUtils.IsMacOS())
29+
_codeInput.SetFocus();
2730
}
2831
}
2932
}

src/shared/GitLab/UI/Views/CredentialsView.axaml.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Avalonia.Controls;
22
using Avalonia.Markup.Xaml;
3+
using GitCredentialManager;
34
using GitLab.UI.ViewModels;
45
using GitCredentialManager.UI.Controls;
56

@@ -48,18 +49,24 @@ public void SetFocus()
4849
else if (vm.ShowTokenLogin)
4950
{
5051
_tabControl.SelectedIndex = 1;
51-
_tokenTextBox.Focus();
52+
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
53+
if (!PlatformUtils.IsMacOS())
54+
_tokenTextBox.Focus();
5255
}
5356
else if (vm.ShowBasicLogin)
5457
{
5558
_tabControl.SelectedIndex = 2;
5659
if (string.IsNullOrWhiteSpace(vm.UserName))
5760
{
58-
_userNameTextBox.Focus();
61+
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
62+
if (!PlatformUtils.IsMacOS())
63+
_userNameTextBox.Focus();
5964
}
6065
else
6166
{
62-
_passwordTextBox.Focus();
67+
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
68+
if (!PlatformUtils.IsMacOS())
69+
_passwordTextBox.Focus();
6370
}
6471
}
6572
}

0 commit comments

Comments
 (0)