Skip to content

Commit f995c73

Browse files
committed
Code Quality: Focus tab content when switching tabs
1 parent 9c2e48b commit f995c73

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

src/Files.App.Controls/Omnibar/Omnibar.Events.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
5656

5757
IsFocused = false;
5858
IsFocusedChanged?.Invoke(this, new(IsFocused));
59-
60-
// Reset to the default mode when Omnibar loses focus
61-
CurrentSelectedMode = Modes?.FirstOrDefault();
6259
}
6360

6461
private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)

src/Files.App/Actions/Navigation/NextTabAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public async Task ExecuteAsync(object? parameter = null)
3636
// Small delay for the UI to load
3737
await Task.Delay(500);
3838

39-
// Refocus on the file list
39+
// Focus the content of the selected tab item (needed for keyboard navigation)
4040
(multitaskingContext.CurrentTabItem.TabItemContent as Control)?.Focus(FocusState.Programmatic);
4141
}
4242

src/Files.App/Actions/Navigation/PreviousTabAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task ExecuteAsync(object? parameter = null)
3939
// Small delay for the UI to load
4040
await Task.Delay(500);
4141

42-
// Refocus on the file list
42+
// Focus the content of the selected tab item (needed for keyboard navigation)
4343
(multitaskingContext.CurrentTabItem.TabItemContent as Control)?.Focus(FocusState.Programmatic);
4444
}
4545

src/Files.App/Data/Contexts/Multitasking/MultitaskingContext.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.UI.Xaml;
5+
using Microsoft.UI.Xaml.Controls;
56
using Microsoft.UI.Xaml.Input;
67
using System.Collections.Specialized;
78

89
namespace Files.App.Data.Contexts
910
{
1011
internal sealed partial class MultitaskingContext : ObservableObject, IMultitaskingContext
1112
{
13+
private readonly MainPageViewModel MainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
14+
1215
private bool isPopupOpen = false;
1316

1417
private ITabBar? control;
@@ -69,6 +72,9 @@ private void FocusManager_GotFocus(object? sender, FocusManagerGotFocusEventArgs
6972
{
7073
int newSelectedIndex = MainPageViewModel.AppInstances.IndexOf(tabItem);
7174
UpdateSelectedTabIndex(newSelectedIndex);
75+
76+
// Focus the content of the selected tab item (needed for pointer navigation)
77+
(MainPageViewModel.SelectedTabItem?.TabItemContent as Control)?.Focus(FocusState.Programmatic);
7278
}
7379
}
7480

src/Files.App/UserControls/NavigationToolbar.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ await DispatcherQueue.EnqueueOrInvokeAsync(() =>
510510
await ViewModel.PopulateOmnibarSuggestionsForSearchMode();
511511
}
512512
}
513+
else
514+
{
515+
Omnibar.CurrentSelectedMode = OmnibarPathMode;
516+
}
513517
}
514518

515519
private async void Omnibar_PreviewKeyDown(object sender, KeyRoutedEventArgs e)

src/Files.App/ViewModels/MainPageViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ private async void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(Keyboa
390390
// Small delay for the UI to load
391391
await Task.Delay(500);
392392

393-
// Refocus on the file list
393+
// Focus the content of the selected tab item (needed for keyboard navigation)
394394
(SelectedTabItem?.TabItemContent as Control)?.Focus(FocusState.Programmatic);
395395
}
396396

0 commit comments

Comments
 (0)