55using Avalonia . Controls ;
66using Avalonia . Data ;
77using Avalonia . Input ;
8- using Avalonia . Input . Platform ;
98using Avalonia . Interactivity ;
109using Avalonia . Markup . Xaml ;
1110using GitCredentialManager ;
@@ -22,8 +21,6 @@ public partial class SixDigitInput : UserControl, IFocusable
2221 ( o , v ) => o . Text = v ,
2322 defaultBindingMode : BindingMode . TwoWay ) ;
2423
25- private PlatformHotkeyConfiguration _keyMap ;
26- private IClipboard _clipboard ;
2724 private bool _ignoreTextBoxUpdate ;
2825 private TextBox [ ] _textBoxes ;
2926 private string _text ;
@@ -37,8 +34,6 @@ private void InitializeComponent()
3734 {
3835 AvaloniaXamlLoader . Load ( this ) ;
3936
40- _keyMap = AvaloniaLocator . Current . GetService < PlatformHotkeyConfiguration > ( ) ;
41- _clipboard = AvaloniaLocator . Current . GetService < IClipboard > ( ) ;
4237 _textBoxes = new [ ]
4338 {
4439 this . FindControl < TextBox > ( "one" ) ,
@@ -89,7 +84,7 @@ public void SetFocus()
8984 {
9085 // Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293
9186 if ( ! PlatformUtils . IsMacOS ( ) )
92- KeyboardDevice . Instance . SetFocusedElement ( _textBoxes [ 0 ] , NavigationMethod . Tab , KeyModifiers . None ) ;
87+ _textBoxes [ 0 ] . Focus ( NavigationMethod . Tab , KeyModifiers . None ) ;
9388 }
9489
9590 private void SetUpTextBox ( TextBox textBox )
@@ -99,7 +94,7 @@ private void SetUpTextBox(TextBox textBox)
9994 void OnPreviewKeyDown ( object sender , KeyEventArgs e )
10095 {
10196 // 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 )
10398 {
10499 OnPaste ( ) ;
105100 e . Handled = true ;
@@ -166,8 +161,7 @@ void OnPreviewKeyDown(object sender, KeyEventArgs e)
166161
167162 private void OnPaste ( )
168163 {
169- string text = _clipboard . GetTextAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
170- Text = text ;
164+ Text = TopLevel . GetTopLevel ( this ) ? . Clipboard ? . GetTextAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
171165 }
172166
173167 private bool MoveNext ( ) => MoveFocus ( true ) ;
@@ -177,7 +171,7 @@ private void OnPaste()
177171 private bool MoveFocus ( bool next )
178172 {
179173 // Get currently focused text box
180- if ( FocusManager . Instance . Current is TextBox textBox )
174+ if ( TopLevel . GetTopLevel ( this ) ? . FocusManager ? . GetFocusedElement ( ) is TextBox textBox )
181175 {
182176 int textBoxIndex = Array . IndexOf ( _textBoxes , textBox ) ;
183177 if ( textBoxIndex > - 1 )
@@ -186,7 +180,7 @@ private bool MoveFocus(bool next)
186180 ? Math . Min ( _textBoxes . Length - 1 , textBoxIndex + 1 )
187181 : Math . Max ( 0 , textBoxIndex - 1 ) ;
188182
189- KeyboardDevice . Instance . SetFocusedElement ( _textBoxes [ nextIndex ] , NavigationMethod . Tab , KeyModifiers . None ) ;
183+ _textBoxes [ nextIndex ] . Focus ( NavigationMethod . Tab , KeyModifiers . None ) ;
190184 return true ;
191185 }
192186 }
0 commit comments