11// Copyright (c) Files Community
22// Licensed under the MIT License.
33
4- using Microsoft . UI . Input ;
54using Microsoft . UI . Xaml . Input ;
65using Windows . System ;
7- using Windows . UI . Core ;
86
97namespace Files . App . Controls
108{
@@ -28,7 +26,7 @@ private void AutoSuggestBox_GettingFocus(UIElement sender, GettingFocusEventArgs
2826
2927 private void AutoSuggestBox_LosingFocus ( UIElement sender , LosingFocusEventArgs args )
3028 {
31- if ( IsModeButtonPressed )
29+ if ( args . NewFocusedElement is Button && IsModeButtonPressed )
3230 {
3331 IsModeButtonPressed = false ;
3432 args . TryCancel ( ) ;
@@ -47,12 +45,16 @@ private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
4745 private void AutoSuggestBox_LostFocus ( object sender , RoutedEventArgs e )
4846 {
4947 // TextBox still has focus if the context menu for selected text is open
50- if ( _textBox . ContextFlyout . IsOpen )
48+ var element = Microsoft . UI . Xaml . Input . FocusManager . GetFocusedElement ( this . XamlRoot ) ;
49+ if ( element is FlyoutBase or Popup )
5150 return ;
5251
5352 GlobalHelper . WriteDebugStringForOmnibar ( "The TextBox lost the focus." ) ;
5453
5554 IsFocused = false ;
55+
56+ // Reset to the default mode when Omnibar loses focus
57+ CurrentSelectedMode = Modes ? . FirstOrDefault ( ) ;
5658 }
5759
5860 private async void AutoSuggestBox_KeyDown ( object sender , KeyRoutedEventArgs e )
@@ -112,16 +114,6 @@ private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)
112114 previouslyFocusedElement ? . Focus ( FocusState . Programmatic ) ;
113115 }
114116 }
115- else if ( e . Key == VirtualKey . Tab && ! InputKeyboardSource . GetKeyStateForCurrentThread ( VirtualKey . Shift ) . HasFlag ( CoreVirtualKeyStates . Down ) )
116- {
117- GlobalHelper . WriteDebugStringForOmnibar ( "The TextBox accepted the Tab key." ) ;
118-
119- // Focus on inactive content when pressing Tab instead of moving to the next control in the tab order
120- e . Handled = true ;
121- IsFocused = false ;
122- await Task . Delay ( 15 ) ;
123- CurrentSelectedMode ? . ContentOnInactive ? . Focus ( FocusState . Keyboard ) ;
124- }
125117 else
126118 {
127119 _textChangeReason = OmnibarTextChangeReason . UserInput ;
@@ -141,6 +133,8 @@ private void AutoSuggestBox_TextChanged(object sender, TextChangedEventArgs e)
141133 _textChangeReason = OmnibarTextChangeReason . UserInput ;
142134 _userInput = _textBox . Text ;
143135 }
136+ else if ( _textChangeReason is OmnibarTextChangeReason . ProgrammaticChange )
137+ _textBox . SelectAll ( ) ;
144138
145139 TextChanged ? . Invoke ( this , new ( CurrentSelectedMode , _textChangeReason ) ) ;
146140
0 commit comments