1
1
// Copyright (c) Files Community
2
2
// Licensed under the MIT License.
3
3
4
- using Microsoft . UI . Input ;
5
4
using Microsoft . UI . Xaml . Input ;
6
5
using Windows . System ;
7
- using Windows . UI . Core ;
8
6
9
7
namespace Files . App . Controls
10
8
{
@@ -28,7 +26,7 @@ private void AutoSuggestBox_GettingFocus(UIElement sender, GettingFocusEventArgs
28
26
29
27
private void AutoSuggestBox_LosingFocus ( UIElement sender , LosingFocusEventArgs args )
30
28
{
31
- if ( IsModeButtonPressed )
29
+ if ( args . NewFocusedElement is Button && IsModeButtonPressed )
32
30
{
33
31
IsModeButtonPressed = false ;
34
32
args . TryCancel ( ) ;
@@ -47,12 +45,16 @@ private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
47
45
private void AutoSuggestBox_LostFocus ( object sender , RoutedEventArgs e )
48
46
{
49
47
// 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 )
51
50
return ;
52
51
53
52
GlobalHelper . WriteDebugStringForOmnibar ( "The TextBox lost the focus." ) ;
54
53
55
54
IsFocused = false ;
55
+
56
+ // Reset to the default mode when Omnibar loses focus
57
+ CurrentSelectedMode = Modes ? . FirstOrDefault ( ) ;
56
58
}
57
59
58
60
private async void AutoSuggestBox_KeyDown ( object sender , KeyRoutedEventArgs e )
@@ -112,16 +114,6 @@ private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)
112
114
previouslyFocusedElement ? . Focus ( FocusState . Programmatic ) ;
113
115
}
114
116
}
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
- }
125
117
else
126
118
{
127
119
_textChangeReason = OmnibarTextChangeReason . UserInput ;
@@ -141,6 +133,8 @@ private void AutoSuggestBox_TextChanged(object sender, TextChangedEventArgs e)
141
133
_textChangeReason = OmnibarTextChangeReason . UserInput ;
142
134
_userInput = _textBox . Text ;
143
135
}
136
+ else if ( _textChangeReason is OmnibarTextChangeReason . ProgrammaticChange )
137
+ _textBox . SelectAll ( ) ;
144
138
145
139
TextChanged ? . Invoke ( this , new ( CurrentSelectedMode , _textChangeReason ) ) ;
146
140
0 commit comments