5
5
using Avalonia . Controls ;
6
6
using Avalonia . Data ;
7
7
using Avalonia . Input ;
8
- using Avalonia . Input . Platform ;
9
8
using Avalonia . Interactivity ;
10
9
using Avalonia . Markup . Xaml ;
11
10
using GitCredentialManager ;
@@ -22,8 +21,6 @@ public partial class SixDigitInput : UserControl, IFocusable
22
21
( o , v ) => o . Text = v ,
23
22
defaultBindingMode : BindingMode . TwoWay ) ;
24
23
25
- private PlatformHotkeyConfiguration _keyMap ;
26
- private IClipboard _clipboard ;
27
24
private bool _ignoreTextBoxUpdate ;
28
25
private TextBox [ ] _textBoxes ;
29
26
private string _text ;
@@ -37,8 +34,6 @@ private void InitializeComponent()
37
34
{
38
35
AvaloniaXamlLoader . Load ( this ) ;
39
36
40
- _keyMap = AvaloniaLocator . Current . GetService < PlatformHotkeyConfiguration > ( ) ;
41
- _clipboard = AvaloniaLocator . Current . GetService < IClipboard > ( ) ;
42
37
_textBoxes = new [ ]
43
38
{
44
39
this . FindControl < TextBox > ( "one" ) ,
@@ -89,7 +84,7 @@ public void SetFocus()
89
84
{
90
85
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
91
86
if ( ! PlatformUtils . IsMacOS ( ) )
92
- KeyboardDevice . Instance . SetFocusedElement ( _textBoxes [ 0 ] , NavigationMethod . Tab , KeyModifiers . None ) ;
87
+ _textBoxes [ 0 ] . Focus ( NavigationMethod . Tab , KeyModifiers . None ) ;
93
88
}
94
89
95
90
private void SetUpTextBox ( TextBox textBox )
@@ -99,7 +94,7 @@ private void SetUpTextBox(TextBox textBox)
99
94
void OnPreviewKeyDown ( object sender , KeyEventArgs e )
100
95
{
101
96
// Handle paste
102
- if ( _keyMap . Paste . Any ( x => x . Matches ( e ) ) )
97
+ if ( TopLevel . GetTopLevel ( this ) ? . PlatformSettings ? . HotkeyConfiguration . Paste . Any ( x => x . Matches ( e ) ) ?? false )
103
98
{
104
99
OnPaste ( ) ;
105
100
e . Handled = true ;
@@ -166,8 +161,7 @@ void OnPreviewKeyDown(object sender, KeyEventArgs e)
166
161
167
162
private void OnPaste ( )
168
163
{
169
- string text = _clipboard . GetTextAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
170
- Text = text ;
164
+ Text = TopLevel . GetTopLevel ( this ) ? . Clipboard ? . GetTextAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
171
165
}
172
166
173
167
private bool MoveNext ( ) => MoveFocus ( true ) ;
@@ -177,7 +171,7 @@ private void OnPaste()
177
171
private bool MoveFocus ( bool next )
178
172
{
179
173
// Get currently focused text box
180
- if ( FocusManager . Instance . Current is TextBox textBox )
174
+ if ( TopLevel . GetTopLevel ( this ) ? . FocusManager ? . GetFocusedElement ( ) is TextBox textBox )
181
175
{
182
176
int textBoxIndex = Array . IndexOf ( _textBoxes , textBox ) ;
183
177
if ( textBoxIndex > - 1 )
@@ -186,7 +180,7 @@ private bool MoveFocus(bool next)
186
180
? Math . Min ( _textBoxes . Length - 1 , textBoxIndex + 1 )
187
181
: Math . Max ( 0 , textBoxIndex - 1 ) ;
188
182
189
- KeyboardDevice . Instance . SetFocusedElement ( _textBoxes [ nextIndex ] , NavigationMethod . Tab , KeyModifiers . None ) ;
183
+ _textBoxes [ nextIndex ] . Focus ( NavigationMethod . Tab , KeyModifiers . None ) ;
190
184
return true ;
191
185
}
192
186
}
0 commit comments