Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 16c60a9

Browse files
committed
Fixed focus issues
1 parent 453151c commit 16c60a9

File tree

13 files changed

+73
-24
lines changed

13 files changed

+73
-24
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Files.App.Actions
99
internal sealed partial class NextTabAction : ObservableObject, IAction
1010
{
1111
private readonly IMultitaskingContext multitaskingContext;
12+
private readonly IContentPageContext contentPageContext = Ioc.Default.GetRequiredService<IContentPageContext>();
1213

1314
public string Label
1415
=> Strings.NextTab.GetLocalizedResource();
@@ -37,7 +38,7 @@ public async Task ExecuteAsync(object? parameter = null)
3738
await Task.Delay(500);
3839

3940
// Focus the content of the selected tab item (needed for keyboard navigation)
40-
(multitaskingContext.CurrentTabItem.TabItemContentasControl)?.Focus(FocusState.Programmatic);
41+
contentPageContext.ShellPage!.PaneHolder.FocusActivePane();
4142
}
4243

4344
private void MultitaskingContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Files.App.Actions
99
internal sealed partial class PreviousTabAction : ObservableObject, IAction
1010
{
1111
private readonly IMultitaskingContext multitaskingContext;
12+
private readonly IContentPageContext contentPageContext = Ioc.Default.GetRequiredService<IContentPageContext>();
1213

1314
public string Label
1415
=> Strings.PreviousTab.GetLocalizedResource();
@@ -40,7 +41,7 @@ public async Task ExecuteAsync(object? parameter = null)
4041
await Task.Delay(500);
4142

4243
// Focus the content of the selected tab item (needed for keyboard navigation)
43-
(multitaskingContext.CurrentTabItem.TabItemContentasControl)?.Focus(FocusState.Programmatic);
44+
contentPageContext.ShellPage!.PaneHolder.FocusActivePane();
4445
}
4546

4647
private void MultitaskingContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)

‎src/Files.App/Data/Contracts/IShellPanesPage.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public interface IShellPanesPage : IDisposable, INotifyPropertyChanged
6969
/// </summary>
7070
public void FocusActivePane();
7171

72+
/// <summary>
73+
/// Locks the active pane.
74+
/// </summary>
75+
public void LockActivePane();
76+
7277
/// <summary>
7378
/// Gets open panes.
7479
/// </summary>

‎src/Files.App/UserControls/TabBar/TabBar.xaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@
261261
HorizontalAlignment="Stretch"
262262
VerticalAlignment="Stretch"
263263
Fill="Transparent"
264-
Loaded="DragAreaRectangle_Loaded"
265-
PointerReleased="DragAreaRectangle_PointerReleased" />
264+
Loaded="DragAreaRectangle_Loaded" />
266265

267266
</Grid>
268267
</TabView.TabStripFooter>

‎src/Files.App/UserControls/TabBar/TabBar.xaml.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,5 @@ private async void DragAreaRectangle_Loaded(object sender, RoutedEventArgs e)
373373
HorizontalTabView.ActualWidth - TabBarAddNewTabButton.Width - titleBarInset,
374374
HorizontalTabView.ActualHeight));
375375
}
376-
377-
private void DragAreaRectangle_PointerReleased(object sender, PointerRoutedEventArgs e)
378-
{
379-
// Workaround for issue where clicking the drag area prevents keyboard
380-
// shortcuts from working, see https://github.com/microsoft/microsoft-ui-xaml/issues/6467
381-
DispatcherQueue.TryEnqueue(() => ContentPageContext.ShellPage!.PaneHolder.FocusActivePane());
382-
}
383376
}
384377
}

‎src/Files.App/UserControls/Toolbar.xaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
BackgroundSizing="InnerBorderEdge"
6161
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
6262
BorderThickness="1"
63-
CornerRadius="8"
64-
PointerReleased="RootGrid_PointerReleased">
63+
CornerRadius="8">
6564
<Grid.ColumnDefinitions>
6665
<ColumnDefinition Width="*" />
6766
<ColumnDefinition Width="Auto" />
@@ -688,7 +687,10 @@
688687
<controls:ThemedIcon Style="{x:Bind ViewModel.LayoutThemedIcon, Mode=OneWay}" />
689688

690689
<AppBarButton.Flyout>
691-
<Flyout contract8Present:ShouldConstrainToRootBounds="False" Placement="Bottom">
690+
<Flyout
691+
x:Name="LayoutFlyout"
692+
contract8Present:ShouldConstrainToRootBounds="False"
693+
Placement="Bottom">
692694
<StackPanel Spacing="12">
693695

694696
<!-- Header -->
@@ -700,6 +702,7 @@
700702
<!-- Details -->
701703
<RadioButton
702704
AutomationProperties.Name="{x:Bind Commands.LayoutDetails.AutomationName}"
705+
Click="LayoutButton_Click"
703706
Command="{x:Bind Commands.LayoutDetails}"
704707
GroupName="LayoutRadio"
705708
IsChecked="{x:Bind ViewModel.IsDetailsLayout, Mode=OneWay}"
@@ -723,6 +726,7 @@
723726
<!-- List -->
724727
<RadioButton
725728
AutomationProperties.Name="{x:Bind Commands.LayoutList.AutomationName}"
729+
Click="LayoutButton_Click"
726730
Command="{x:Bind Commands.LayoutList}"
727731
GroupName="LayoutRadio"
728732
IsChecked="{x:Bind ViewModel.IsListLayout, Mode=OneWay}"
@@ -747,6 +751,7 @@
747751
<!-- Cards -->
748752
<RadioButton
749753
AutomationProperties.Name="{x:Bind Commands.LayoutCards.AutomationName}"
754+
Click="LayoutButton_Click"
750755
Command="{x:Bind Commands.LayoutCards}"
751756
GroupName="LayoutRadio"
752757
IsChecked="{x:Bind ViewModel.IsCardsLayout, Mode=OneWay}"
@@ -771,6 +776,7 @@
771776
<!-- Grid -->
772777
<RadioButton
773778
AutomationProperties.Name="{x:Bind Commands.LayoutGrid.AutomationName}"
779+
Click="LayoutButton_Click"
774780
Command="{x:Bind Commands.LayoutGrid}"
775781
GroupName="LayoutRadio"
776782
IsChecked="{x:Bind ViewModel.IsGridLayout, Mode=OneWay}"
@@ -795,6 +801,7 @@
795801
<!-- Columns -->
796802
<RadioButton
797803
AutomationProperties.Name="{x:Bind Commands.LayoutColumns.AutomationName}"
804+
Click="LayoutButton_Click"
798805
Command="{x:Bind Commands.LayoutColumns}"
799806
GroupName="LayoutRadio"
800807
IsChecked="{x:Bind ViewModel.IsColumnLayout, Mode=OneWay}"

‎src/Files.App/UserControls/Toolbar.xaml.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public sealed partial class Toolbar : UserControl
1717
private readonly ICommandManager Commands = Ioc.Default.GetRequiredService<ICommandManager>();
1818
private readonly IModifiableCommandManager ModifiableCommands = Ioc.Default.GetRequiredService<IModifiableCommandManager>();
1919
private readonly IAddItemService addItemService = Ioc.Default.GetRequiredService<IAddItemService>();
20-
private readonly IContentPageContext ContentPageContext = Ioc.Default.GetRequiredService<IContentPageContext>();
2120

2221
[GeneratedDependencyProperty]
2322
public partial NavigationToolbarViewModel? ViewModel { get; set; }
@@ -110,11 +109,10 @@ private void AppBarButton_AccessKeyInvoked(UIElement sender, AccessKeyInvokedEve
110109
args.Handled = true;
111110
}
112111

113-
private void RootGrid_PointerReleased(object sender, PointerRoutedEventArgs e)
112+
private void LayoutButton_Click(object sender, RoutedEventArgs e)
114113
{
115-
// Workaround for issue where clicking the toolbar prevents keyboard
116-
// shortcuts from working, see https://github.com/microsoft/microsoft-ui-xaml/issues/6467
117-
DispatcherQueue.TryEnqueue(() => ContentPageContext.ShellPage!.PaneHolder.FocusActivePane());
114+
// Hide flyout after choosing a layout
115+
LayoutFlyout.Hide();
118116
}
119117
}
120118
}

‎src/Files.App/ViewModels/MainPageViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private async void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(Keyboa
391391
await Task.Delay(500);
392392

393393
// Focus the content of the selected tab item (needed for keyboard navigation)
394-
(SelectedTabItem?.TabItemContentasControl)?.Focus(FocusState.Programmatic);
394+
context.ShellPage!.PaneHolder.FocusActivePane();
395395
}
396396

397397
e.Handled = true;

‎src/Files.App/ViewModels/ShellViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,13 @@ public ShellViewModel(LayoutPreferencesManager folderSettingsViewModel)
584584

585585
private async void LayoutModeChangeRequested(object? sender, LayoutModeEventArgs e)
586586
{
587+
// Layout changes can cause the active pane to lose focus. To prevent this,
588+
// the pane is locked here and focus is restored when file loading completes
589+
// in the RefreshItem() method in BaseLayoutPage.cs.
590+
// See https://github.com/files-community/Files/issues/15397
591+
// See https://github.com/files-community/Files/issues/16530
592+
ContentPageContext.ShellPage!.PaneHolder.LockActivePane();
593+
587594
await dispatcherQueue.EnqueueOrInvokeAsync(CheckForBackgroundImage, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
588595
}
589596

‎src/Files.App/Views/Layouts/BaseLayoutPage.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,8 +1240,14 @@ private void RefreshItem(SelectorItem container, object item, bool inRecycleQueu
12401240
if (ParentShellPageInstance.ShellViewModel.EnabledGitProperties is not GitProperties.None && listedItem is IGitItem gitItem)
12411241
await ParentShellPageInstance.ShellViewModel.LoadGitPropertiesAsync(gitItem);
12421242

1243-
// Focus file list when items finish loading (#16530)
1244-
ItemManipulationModel.FocusFileList();
1243+
// Layout changes can cause the active pane to lose focus. To prevent this,
1244+
// the pane is locked in LayoutModeChangeRequested() and focus is restored here
1245+
// when file loading completes.
1246+
// See https://github.com/files-community/Files/issues/15397
1247+
// See https://github.com/files-community/Files/issues/16530
1248+
1249+
if (ParentShellPageInstance.IsCurrentPane && !ParentShellPageInstance.IsColumnView)
1250+
ItemManipulationModel.FocusFileList();
12451251
});
12461252
}
12471253
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /