Skip to content

Commit 453151c

Browse files
committed
Code Quality: Fixed keyboard shortcuts when refocusing window
1 parent 23eec92 commit 453151c

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
x:Name="SplitPaneMenuItem"
146146
x:Load="{x:Bind Commands.SplitPaneHorizontally.IsExecutable, Mode=OneWay}"
147147
Text="{helpers:ResourceString Name=SplitPane}">
148-
<MenuFlyoutSubItem.Items>
148+
<MenuFlyoutSubItem.Items>
149149
<!-- Vertical -->
150150
<uc:MenuFlyoutItemWithThemedIcon
151151
x:Name="AddVerticalPaneTabActionButton"
@@ -261,7 +261,8 @@
261261
HorizontalAlignment="Stretch"
262262
VerticalAlignment="Stretch"
263263
Fill="Transparent"
264-
Loaded="DragAreaRectangle_Loaded" />
264+
Loaded="DragAreaRectangle_Loaded"
265+
PointerReleased="DragAreaRectangle_PointerReleased" />
265266

266267
</Grid>
267268
</TabView.TabStripFooter>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public sealed partial class TabBar : BaseTabBar, INotifyPropertyChanged
1919
private readonly ICommandManager Commands = Ioc.Default.GetRequiredService<ICommandManager>();
2020
private readonly IAppearanceSettingsService AppearanceSettingsService = Ioc.Default.GetRequiredService<IAppearanceSettingsService>();
2121
private readonly IWindowContext WindowContext = Ioc.Default.GetRequiredService<IWindowContext>();
22+
private readonly IContentPageContext ContentPageContext = Ioc.Default.GetRequiredService<IContentPageContext>();
2223

2324
// Fields
2425

@@ -372,5 +373,12 @@ private async void DragAreaRectangle_Loaded(object sender, RoutedEventArgs e)
372373
HorizontalTabView.ActualWidth - TabBarAddNewTabButton.Width - titleBarInset,
373374
HorizontalTabView.ActualHeight));
374375
}
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+
}
375383
}
376384
}

src/Files.App/UserControls/Toolbar.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
BackgroundSizing="InnerBorderEdge"
6161
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
6262
BorderThickness="1"
63-
CornerRadius="8">
63+
CornerRadius="8"
64+
PointerReleased="RootGrid_PointerReleased">
6465
<Grid.ColumnDefinitions>
6566
<ColumnDefinition Width="*" />
6667
<ColumnDefinition Width="Auto" />

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ 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>();
2021

2122
[GeneratedDependencyProperty]
2223
public partial NavigationToolbarViewModel? ViewModel { get; set; }
@@ -108,5 +109,12 @@ private void AppBarButton_AccessKeyInvoked(UIElement sender, AccessKeyInvokedEve
108109
if (VisualTreeHelper.GetOpenPopupsForXamlRoot(MainWindow.Instance.Content.XamlRoot).Any())
109110
args.Handled = true;
110111
}
112+
113+
private void RootGrid_PointerReleased(object sender, PointerRoutedEventArgs e)
114+
{
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());
118+
}
111119
}
112120
}

src/Files.App/Views/MainPage.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ public async void MultitaskingControl_CurrentInstanceChanged(object? sender, Cur
162162
// Focus the content of the selected tab item (this also avoids an issue where the Omnibar sometimes steals the focus)
163163
await Task.Delay(100);
164164
ContentPageContext.ShellPage!.PaneHolder.FocusActivePane();
165-
166165
}
167166

168167
private void PaneHolder_PropertyChanged(object? sender, PropertyChangedEventArgs e)

0 commit comments

Comments
 (0)