diff --git a/src/Files.App/Actions/Navigation/NextTabAction.cs b/src/Files.App/Actions/Navigation/NextTabAction.cs index 6bbe1dc5db59..38eb469c817c 100644 --- a/src/Files.App/Actions/Navigation/NextTabAction.cs +++ b/src/Files.App/Actions/Navigation/NextTabAction.cs @@ -1,6 +1,9 @@ // Copyright (c) 2024 Files Community // Licensed under the MIT License. See the LICENSE. +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; + namespace Files.App.Actions { internal sealed class NextTabAction : ObservableObject, IAction @@ -26,11 +29,15 @@ public NextTabAction() multitaskingContext.PropertyChanged += MultitaskingContext_PropertyChanged; } - public Task ExecuteAsync(object? parameter = null) + public async Task ExecuteAsync(object? parameter = null) { App.AppModel.TabStripSelectedIndex = (App.AppModel.TabStripSelectedIndex + 1) % multitaskingContext.TabCount; - return Task.CompletedTask; + // Small delay for the UI to load + await Task.Delay(500); + + // Refocus on the file list + (multitaskingContext.CurrentTabItem.TabItemContent as Control)?.Focus(FocusState.Programmatic); } private void MultitaskingContext_PropertyChanged(object? sender, PropertyChangedEventArgs e) diff --git a/src/Files.App/Actions/Navigation/PreviousTabAction.cs b/src/Files.App/Actions/Navigation/PreviousTabAction.cs index 84989d7b70b1..e1f008895d90 100644 --- a/src/Files.App/Actions/Navigation/PreviousTabAction.cs +++ b/src/Files.App/Actions/Navigation/PreviousTabAction.cs @@ -1,6 +1,9 @@ // Copyright (c) 2024 Files Community // Licensed under the MIT License. See the LICENSE. +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; + namespace Files.App.Actions { internal sealed class PreviousTabAction : ObservableObject, IAction @@ -26,14 +29,18 @@ public PreviousTabAction() multitaskingContext.PropertyChanged += MultitaskingContext_PropertyChanged; } - public Task ExecuteAsync(object? parameter = null) + public async Task ExecuteAsync(object? parameter = null) { if (App.AppModel.TabStripSelectedIndex is 0) App.AppModel.TabStripSelectedIndex = multitaskingContext.TabCount - 1; else App.AppModel.TabStripSelectedIndex--; - return Task.CompletedTask; + // Small delay for the UI to load + await Task.Delay(500); + + // Refocus on the file list + (multitaskingContext.CurrentTabItem.TabItemContent as Control)?.Focus(FocusState.Programmatic); } private void MultitaskingContext_PropertyChanged(object? sender, PropertyChangedEventArgs e) diff --git a/src/Files.App/Data/Models/AppModel.cs b/src/Files.App/Data/Models/AppModel.cs index e3f045bb44f4..d9a5c5d180ab 100644 --- a/src/Files.App/Data/Models/AppModel.cs +++ b/src/Files.App/Data/Models/AppModel.cs @@ -37,7 +37,7 @@ public int TabStripSelectedIndex if (value >= 0 && value < MainPageViewModel.AppInstances.Count) { - Frame rootFrame = (Frame)MainWindow.Instance.Content; + var rootFrame = (Frame)MainWindow.Instance.Content; var mainView = (MainPage)rootFrame.Content; mainView.ViewModel.SelectedTabItem = MainPageViewModel.AppInstances[value]; } diff --git a/src/Files.App/ViewModels/MainPageViewModel.cs b/src/Files.App/ViewModels/MainPageViewModel.cs index 91eeabf8e254..f141bbde7a22 100644 --- a/src/Files.App/ViewModels/MainPageViewModel.cs +++ b/src/Files.App/ViewModels/MainPageViewModel.cs @@ -8,6 +8,7 @@ using Microsoft.UI.Xaml.Navigation; using System.Windows.Input; using Windows.System; +using Microsoft.UI.Xaml.Controls; namespace Files.App.ViewModels { @@ -228,9 +229,9 @@ await Task.WhenAll( // Command methods - private void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcceleratorInvokedEventArgs? e) + private async void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcceleratorInvokedEventArgs? e) { - int indexToSelect = e!.KeyboardAccelerator.Key switch + var indexToSelect = e!.KeyboardAccelerator.Key switch { VirtualKey.Number1 => 0, VirtualKey.Number2 => 1, @@ -246,8 +247,16 @@ private void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcce // Only select the tab if it is in the list if (indexToSelect < AppInstances.Count) + { App.AppModel.TabStripSelectedIndex = indexToSelect; + // Small delay for the UI to load + await Task.Delay(500); + + // Refocus on the file list + (SelectedTabItem?.TabItemContent as Control)?.Focus(FocusState.Programmatic); + } + e.Handled = true; }