Skip to content

Code Quality: Fixed tab key navigation in Omnibar #17219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Files.App.Controls/Omnibar/Omnibar.Events.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -47,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)
{
Expand Down Expand Up @@ -98,6 +100,14 @@ 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))
{
// 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;
Expand Down
43 changes: 25 additions & 18 deletions src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down
Loading