From ae33dfb0cd40cae593fe387cc8de3bf765040b8d Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 25 Jun 2025 21:30:19 -0400 Subject: [PATCH 1/7] Code Quality: Fixed tab key navigation in Omnibar --- .../Omnibar/Omnibar.Events.cs | 11 ++++- .../NavigationToolbarViewModel.cs | 43 +++++++++++-------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs index bdb8de3e3fac..e91ff56db9c2 100644 --- a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs +++ b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs @@ -1,8 +1,10 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using Microsoft.UI.Input; using Microsoft.UI.Xaml.Input; using Windows.System; +using Windows.UI.Core; namespace Files.App.Controls { @@ -22,7 +24,7 @@ private void AutoSuggestBox_GettingFocus(UIElement sender, GettingFocusEventArgs _previouslyFocusedElement = new(args.OldFocusedElement as UIElement); } - private void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEventArgs args) + private async void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEventArgs args) { if (IsModeButtonPressed) { @@ -30,6 +32,13 @@ private void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEventArgs a args.TryCancel(); return; } + + var keyState = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Tab); + if (keyState.HasFlag(CoreVirtualKeyStates.Down)) + { + await Task.Delay(10); + CurrentSelectedMode?.ContentOnInactive?.Focus(FocusState.Keyboard); + } } private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e) diff --git a/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs b/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs index 216f0835c966..7aad2035dddd 100644 --- a/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs @@ -1209,31 +1209,38 @@ public void PopulateOmnibarSuggestionsForCommandPaletteMode() dispatcherQueue.TryEnqueue(() => { - var selectedItemPath = ContentPageContext.SelectedItem.ItemPath; - var fileActionEntity = ActionManager.Instance.EntityFactory.CreateFileEntity(selectedItemPath); - var actions = ActionManager.Instance.ActionRuntime.ActionCatalog.GetActionsForInputs(new[] { fileActionEntity }); - - foreach (var action in actions.Where(a => a.Definition.Description.Contains(OmnibarCommandPaletteModeText, StringComparison.OrdinalIgnoreCase))) + try { - var newItem = new NavigationBarSuggestionItem - { - PrimaryDisplay = action.Definition.Description, - SearchText = OmnibarCommandPaletteModeText, - ActionInstance = action - }; + var selectedItemPath = ContentPageContext.SelectedItem.ItemPath; + var fileActionEntity = ActionManager.Instance.EntityFactory.CreateFileEntity(selectedItemPath); + var actions = ActionManager.Instance.ActionRuntime.ActionCatalog.GetActionsForInputs(new[] { fileActionEntity }); - if (Uri.TryCreate(action.Definition.IconFullPath, UriKind.RelativeOrAbsolute, out Uri? validUri)) + foreach (var action in actions.Where(a => a.Definition.Description.Contains(OmnibarCommandPaletteModeText, StringComparison.OrdinalIgnoreCase))) { - try + var newItem = new NavigationBarSuggestionItem { - newItem.ActionIconSource = new BitmapImage(validUri); - } - catch (Exception) + PrimaryDisplay = action.Definition.Description, + SearchText = OmnibarCommandPaletteModeText, + ActionInstance = action + }; + + if (Uri.TryCreate(action.Definition.IconFullPath, UriKind.RelativeOrAbsolute, out Uri? validUri)) { + try + { + newItem.ActionIconSource = new BitmapImage(validUri); + } + catch (Exception) + { + } } - } - OmnibarCommandPaletteModeSuggestionItems.Add(newItem); + OmnibarCommandPaletteModeSuggestionItems.Add(newItem); + } + } + catch (Exception ex) + { + App.Logger.LogWarning(ex, ex.Message); } }); } From 4a6e469321a988aba740f0851501ba47a5840cd6 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 25 Jun 2025 22:36:17 -0400 Subject: [PATCH 2/7] Update Omnibar.Events.cs --- src/Files.App.Controls/Omnibar/Omnibar.Events.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs index e91ff56db9c2..acecc1837e2d 100644 --- a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs +++ b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs @@ -36,7 +36,7 @@ private async void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEvent var keyState = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Tab); if (keyState.HasFlag(CoreVirtualKeyStates.Down)) { - await Task.Delay(10); + await Task.Delay(1); CurrentSelectedMode?.ContentOnInactive?.Focus(FocusState.Keyboard); } } From d7ca7be8caff040062ed6f309283bf50d2765f5a Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 25 Jun 2025 22:48:41 -0400 Subject: [PATCH 3/7] Update Omnibar.Events.cs --- src/Files.App.Controls/Omnibar/Omnibar.Events.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs index acecc1837e2d..ebdfe7ea511f 100644 --- a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs +++ b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs @@ -36,7 +36,7 @@ private async void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEvent var keyState = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Tab); if (keyState.HasFlag(CoreVirtualKeyStates.Down)) { - await Task.Delay(1); + await Task.Delay(2); CurrentSelectedMode?.ContentOnInactive?.Focus(FocusState.Keyboard); } } From 96f9e03d0f592e57f5ad11bddde6f2badc6991f5 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 25 Jun 2025 22:50:38 -0400 Subject: [PATCH 4/7] Update Omnibar.Events.cs --- src/Files.App.Controls/Omnibar/Omnibar.Events.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs index ebdfe7ea511f..e91ff56db9c2 100644 --- a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs +++ b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs @@ -36,7 +36,7 @@ private async void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEvent var keyState = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Tab); if (keyState.HasFlag(CoreVirtualKeyStates.Down)) { - await Task.Delay(2); + await Task.Delay(10); CurrentSelectedMode?.ContentOnInactive?.Focus(FocusState.Keyboard); } } From 4496ac3b35ee8718ee689ea381e8920df7ed1b82 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 25 Jun 2025 23:09:32 -0400 Subject: [PATCH 5/7] Update Omnibar.Events.cs --- src/Files.App.Controls/Omnibar/Omnibar.Events.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs index e91ff56db9c2..e5c758b1ba8e 100644 --- a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs +++ b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs @@ -36,7 +36,7 @@ private async void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEvent var keyState = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Tab); if (keyState.HasFlag(CoreVirtualKeyStates.Down)) { - await Task.Delay(10); + await Task.Delay(15); CurrentSelectedMode?.ContentOnInactive?.Focus(FocusState.Keyboard); } } From 96b5b3e967c1962c27f8e70deba4406a01018cac Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Thu, 26 Jun 2025 11:24:25 -0400 Subject: [PATCH 6/7] Fixed tab nav --- .../Omnibar/Omnibar.Events.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs index e5c758b1ba8e..ba8ab9997ccf 100644 --- a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs +++ b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs @@ -24,7 +24,7 @@ private void AutoSuggestBox_GettingFocus(UIElement sender, GettingFocusEventArgs _previouslyFocusedElement = new(args.OldFocusedElement as UIElement); } - private async void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEventArgs args) + private void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEventArgs args) { if (IsModeButtonPressed) { @@ -32,13 +32,6 @@ private async void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEvent args.TryCancel(); return; } - - var keyState = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Tab); - if (keyState.HasFlag(CoreVirtualKeyStates.Down)) - { - await Task.Delay(15); - CurrentSelectedMode?.ContentOnInactive?.Focus(FocusState.Keyboard); - } } private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e) @@ -56,7 +49,7 @@ private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e) IsFocused = false; } - private void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e) + private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e) { if (e.Key is VirtualKey.Enter) { @@ -107,6 +100,13 @@ private void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e) previouslyFocusedElement?.Focus(FocusState.Programmatic); } } + else if (e.Key == VirtualKey.Tab && !InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down)) + { + e.Handled = true; + IsFocused = false; + await Task.Delay(15); + CurrentSelectedMode?.ContentOnInactive?.Focus(FocusState.Keyboard); + } else { _textChangeReason = OmnibarTextChangeReason.UserInput; From 74ab99ec4bb17c3aedb7aa24e6b1710130b598ac Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Fri, 27 Jun 2025 11:24:07 -0400 Subject: [PATCH 7/7] Added comment --- src/Files.App.Controls/Omnibar/Omnibar.Events.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs index ba8ab9997ccf..f3f0459d0624 100644 --- a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs +++ b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs @@ -102,6 +102,7 @@ private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e) } 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);