diff --git a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs index f3f0459d0624..613f77572824 100644 --- a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs +++ b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs @@ -15,6 +15,12 @@ private void Omnibar_SizeChanged(object sender, SizeChangedEventArgs e) // Popup width has to be set manually because it doesn't stretch with the parent _textBoxSuggestionsContainerBorder.Width = ActualWidth; } + + private void Omnibar_LostFocus(object sender, RoutedEventArgs e) + { + // Reset to the default mode when Omnibar loses focus + CurrentSelectedMode = Modes?.FirstOrDefault(); + } private void AutoSuggestBox_GettingFocus(UIElement sender, GettingFocusEventArgs args) { @@ -100,14 +106,6 @@ private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e) previouslyFocusedElement?.Focus(FocusState.Programmatic); } } - else if (e.Key == VirtualKey.Tab && !InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down)) - { - // Focus on inactive content when pressing Tab instead of moving to the next control in the tab order - e.Handled = true; - IsFocused = false; - await Task.Delay(15); - CurrentSelectedMode?.ContentOnInactive?.Focus(FocusState.Keyboard); - } else { _textChangeReason = OmnibarTextChangeReason.UserInput; @@ -127,6 +125,8 @@ private void AutoSuggestBox_TextChanged(object sender, TextChangedEventArgs e) _textChangeReason = OmnibarTextChangeReason.UserInput; _userInput = _textBox.Text; } + else if (_textChangeReason is OmnibarTextChangeReason.ProgrammaticChange) + _textBox.SelectAll(); TextChanged?.Invoke(this, new(CurrentSelectedMode, _textChangeReason)); diff --git a/src/Files.App.Controls/Omnibar/Omnibar.cs b/src/Files.App.Controls/Omnibar/Omnibar.cs index f404a66e3381..65c9e4ae275e 100644 --- a/src/Files.App.Controls/Omnibar/Omnibar.cs +++ b/src/Files.App.Controls/Omnibar/Omnibar.cs @@ -73,6 +73,7 @@ protected override void OnApplyTemplate() PopulateModes(); SizeChanged += Omnibar_SizeChanged; + LostFocus += Omnibar_LostFocus; _textBox.GettingFocus += AutoSuggestBox_GettingFocus; _textBox.GotFocus += AutoSuggestBox_GotFocus; _textBox.LosingFocus += AutoSuggestBox_LosingFocus; diff --git a/src/Files.App/UserControls/NavigationToolbar.xaml b/src/Files.App/UserControls/NavigationToolbar.xaml index acf1697fc5f4..5d4a2db52e38 100644 --- a/src/Files.App/UserControls/NavigationToolbar.xaml +++ b/src/Files.App/UserControls/NavigationToolbar.xaml @@ -351,7 +351,7 @@ x:Load="{x:Bind ViewModel.EnableOmnibar, Mode=OneWay}" CurrentSelectedModeName="{x:Bind ViewModel.OmnibarCurrentSelectedModeName, Mode=TwoWay}" IsFocused="{x:Bind ViewModel.IsOmnibarFocused, Mode=TwoWay}" - LostFocus="Omnibar_LostFocus" + ModeChanged="Omnibar_ModeChanged" PreviewKeyDown="Omnibar_PreviewKeyDown" QuerySubmitted="Omnibar_QuerySubmitted" TextChanged="Omnibar_TextChanged"> diff --git a/src/Files.App/UserControls/NavigationToolbar.xaml.cs b/src/Files.App/UserControls/NavigationToolbar.xaml.cs index 900d19f769d6..d13cba57089a 100644 --- a/src/Files.App/UserControls/NavigationToolbar.xaml.cs +++ b/src/Files.App/UserControls/NavigationToolbar.xaml.cs @@ -12,6 +12,7 @@ using Microsoft.UI.Xaml.Navigation; using Windows.AI.Actions.Hosting; using Windows.System; +using Windows.UI.Core; namespace Files.App.UserControls { @@ -427,22 +428,31 @@ private void BreadcrumbBar_ItemDropDownFlyoutClosed(object sender, BreadcrumbBar e.Flyout.Items.Clear(); } - private void Omnibar_LostFocus(object sender, RoutedEventArgs e) + private void Omnibar_ModeChanged(object sender, OmnibarModeChangedEventArgs e) { + // Reset the command palette text when switching modes if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode) - { - Omnibar.CurrentSelectedMode = OmnibarPathMode; ViewModel.OmnibarCommandPaletteModeText = string.Empty; - } } - private void Omnibar_PreviewKeyDown(object sender, KeyRoutedEventArgs e) + private async void Omnibar_PreviewKeyDown(object sender, KeyRoutedEventArgs e) { if (e.Key is VirtualKey.Escape) { Omnibar.IsFocused = false; (MainPageViewModel.SelectedTabItem?.TabItemContent as Control)?.Focus(FocusState.Programmatic); } + else if (e.Key is VirtualKey.Tab && Omnibar.IsFocused && !InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down)) + { + var currentSelectedMode = Omnibar.CurrentSelectedMode; + Omnibar.IsFocused = false; + await Task.Delay(15); + + if (currentSelectedMode == OmnibarPathMode) + BreadcrumbBar.Focus(FocusState.Keyboard); + else if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode) + OmnibarCommandPaletteMode.Focus(FocusState.Keyboard); + } } private void NavigationButtonOverflowFlyoutButton_LosingFocus(UIElement sender, LosingFocusEventArgs args)