Skip to content

Commit

Permalink
Fix file list being unfocused when changing tabs using keys
Browse files Browse the repository at this point in the history
  • Loading branch information
d2dyno1 committed May 22, 2024
1 parent 4b77a5a commit dcda3aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/Files.App/Actions/Navigation/PreviousTabAction.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,14 +29,15 @@ 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;
await Task.Delay(500);
(multitaskingContext.CurrentTabItem.TabItemContent as Control)?.Focus(FocusState.Programmatic);
}

private void MultitaskingContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Data/Models/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
13 changes: 9 additions & 4 deletions src/Files.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See the LICENSE.

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
Expand Down Expand Up @@ -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,
Expand All @@ -244,12 +245,16 @@ private void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcce
_ => AppInstances.Count - 1,
};

e.Handled = true;

// Only select the tab if it is in the list
if (indexToSelect < AppInstances.Count)
{
App.AppModel.TabStripSelectedIndex = indexToSelect;

e.Handled = true;
await Task.Delay(500);
(SelectedTabItem?.TabItemContent as Control)?.Focus(FocusState.Programmatic);
}
}

}
}

0 comments on commit dcda3aa

Please sign in to comment.