Skip to content

Commit e1c4c3b

Browse files
Fix: Fixed issue where Alt-Up focused on the column header (#10633)
1 parent 2867c97 commit e1c4c3b

File tree

7 files changed

+37
-19
lines changed

7 files changed

+37
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private void VisiblePath_KeyDown(object _, KeyRoutedEventArgs e)
105105
}
106106
private void VisiblePath_LostFocus(object _, RoutedEventArgs e)
107107
{
108-
var element = FocusManager.GetFocusedElement();
108+
var element = FocusManager.GetFocusedElement(XamlRoot);
109109
if (element is FlyoutBase or AppBarButton or Popup)
110110
return;
111111

src/Files.App/Views/LayoutModes/ColumnViewBase.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,12 @@
163163
DragItemsStarting="FileList_DragItemsStarting"
164164
DragOver="ItemsLayout_DragOver"
165165
Drop="ItemsLayout_Drop"
166+
FocusVisualPrimaryThickness="0"
167+
FocusVisualSecondaryThickness="0"
166168
Holding="FileList_Holding"
167169
IsDoubleTapEnabled="True"
168170
IsRightTapEnabled="True"
171+
IsTabStop="True"
169172
ItemsSource="{x:Bind CollectionViewSource.View, Mode=OneWay}"
170173
PreviewKeyDown="FileList_PreviewKeyDown"
171174
PreviewKeyUp="FileList_PreviewKeyUp"

src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ private void ItemManipulationModel_SelectAllItemsInvoked(object? sender, EventAr
150150

151151
private void ItemManipulationModel_FocusFileListInvoked(object? sender, EventArgs e)
152152
{
153-
FileList.Focus(FocusState.Programmatic);
153+
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
154+
var isFileListFocused = DependencyObjectHelpers.FindParent<ListViewBase>(focusedElement) == FileList;
155+
if (!isFileListFocused)
156+
FileList.Focus(FocusState.Programmatic);
154157
}
155158

156159
private void ZoomIn(object? sender, GroupOption option)
@@ -279,7 +282,7 @@ private void RenameTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
279282
private void RenameTextBox_LostFocus(object sender, RoutedEventArgs e)
280283
{
281284
// This check allows the user to use the text box context menu without ending the rename
282-
if (!(FocusManager.GetFocusedElement() is AppBarButton or Popup))
285+
if (!(FocusManager.GetFocusedElement(XamlRoot) is AppBarButton or Popup))
283286
{
284287
TextBox textBox = (TextBox)e.OriginalSource;
285288
CommitRename(textBox);
@@ -430,12 +433,12 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
430433
else if (e.KeyStatus.IsMenuKeyDown && (e.Key == VirtualKey.Left || e.Key == VirtualKey.Right || e.Key == VirtualKey.Up))
431434
{
432435
// Unfocus the GridView so keyboard shortcut can be handled
433-
NavToolbar?.Focus(FocusState.Pointer);
436+
this.Focus(FocusState.Pointer);
434437
}
435438
else if (e.KeyStatus.IsMenuKeyDown && shiftPressed && e.Key == VirtualKey.Add)
436439
{
437440
// Unfocus the ListView so keyboard shortcut can be handled (alt + shift + "+")
438-
NavToolbar?.Focus(FocusState.Pointer);
441+
this.Focus(FocusState.Pointer);
439442
}
440443
else if (e.Key == VirtualKey.Up || e.Key == VirtualKey.Down)
441444
{
@@ -477,7 +480,7 @@ protected override void Page_CharacterReceived(UIElement sender, CharacterReceiv
477480
return;
478481

479482
// Don't block the various uses of enter key (key 13)
480-
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement();
483+
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
481484

482485
if
483486
(

src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,17 @@
219219
tui:ScrollViewerExtensions.EnableMiddleClickScrolling="{x:Bind IsMiddleClickToScrollEnabled, Mode=OneWay}"
220220
x:FieldModifier="public"
221221
AllowDrop="{x:Bind InstanceViewModel.IsPageTypeSearchResults, Converter={StaticResource BoolNegationConverter}, Mode=OneWay}"
222+
AutomationProperties.AccessibilityView="Raw"
222223
CanDragItems="True"
223224
ContainerContentChanging="FileList_ContainerContentChanging"
224225
DoubleTapped="FileList_DoubleTapped"
225226
DragItemsStarting="FileList_DragItemsStarting"
226227
DragOver="ItemsLayout_DragOver"
227228
Drop="ItemsLayout_Drop"
229+
FocusVisualPrimaryThickness="0"
230+
FocusVisualSecondaryThickness="0"
228231
IsDoubleTapEnabled="True"
232+
IsTabStop="True"
229233
ItemsSource="{x:Bind CollectionViewSource.View, Mode=OneWay}"
230234
Loaded="FileList_Loaded"
231235
PreviewKeyDown="FileList_PreviewKeyDown"

src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ private void ItemManipulationModel_SelectAllItemsInvoked(object? sender, EventAr
148148

149149
private void ItemManipulationModel_FocusFileListInvoked(object? sender, EventArgs e)
150150
{
151-
FileList.Focus(FocusState.Programmatic);
151+
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
152+
var isFileListFocused = DependencyObjectHelpers.FindParent<ListViewBase>(focusedElement) == FileList;
153+
if (!isFileListFocused)
154+
FileList.Focus(FocusState.Programmatic);
152155
}
153156

154157
private void ZoomIn(object? sender, GroupOption option)
@@ -374,7 +377,7 @@ private void RenameTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
374377
private void RenameTextBox_LostFocus(object sender, RoutedEventArgs e)
375378
{
376379
// This check allows the user to use the text box context menu without ending the rename
377-
if (!(FocusManager.GetFocusedElement() is AppBarButton or Popup))
380+
if (!(FocusManager.GetFocusedElement(XamlRoot) is AppBarButton or Popup))
378381
{
379382
TextBox? textBox = e.OriginalSource as TextBox;
380383
CommitRename(textBox!);
@@ -419,7 +422,7 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
419422
{
420423
var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
421424
var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
422-
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement();
425+
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
423426
var isHeaderFocused = DependencyObjectHelpers.FindParent<DataGridHeader>(focusedElement) is not null;
424427
var isFooterFocused = focusedElement is HyperlinkButton;
425428

@@ -460,12 +463,12 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
460463
else if (e.KeyStatus.IsMenuKeyDown && (e.Key == VirtualKey.Left || e.Key == VirtualKey.Right || e.Key == VirtualKey.Up))
461464
{
462465
// Unfocus the GridView so keyboard shortcut can be handled
463-
NavToolbar?.Focus(FocusState.Pointer);
466+
this.Focus(FocusState.Pointer);
464467
}
465468
else if (e.KeyStatus.IsMenuKeyDown && shiftPressed && e.Key == VirtualKey.Add)
466469
{
467470
// Unfocus the ListView so keyboard shortcut can be handled (alt + shift + "+")
468-
NavToolbar?.Focus(FocusState.Pointer);
471+
this.Focus(FocusState.Pointer);
469472
}
470473
else if (e.Key == VirtualKey.Down)
471474
{
@@ -491,7 +494,7 @@ protected override void Page_CharacterReceived(UIElement sender, CharacterReceiv
491494
if (ParentShellPageInstance.CurrentPageType == typeof(DetailsLayoutBrowser) && !IsRenamingItem)
492495
{
493496
// Don't block the various uses of enter key (key 13)
494-
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement();
497+
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
495498
var isHeaderFocused = DependencyObjectHelpers.FindParent<DataGridHeader>(focusedElement) is not null;
496499
if (Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Enter) == CoreVirtualKeyStates.Down
497500
|| (focusedElement is Button && !isHeaderFocused) // Allow jumpstring when header is focused

src/Files.App/Views/LayoutModes/GridViewBrowser.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,10 @@
517517
DragItemsStarting="FileList_DragItemsStarting"
518518
DragOver="ItemsLayout_DragOver"
519519
Drop="ItemsLayout_Drop"
520+
FocusVisualPrimaryThickness="0"
521+
FocusVisualSecondaryThickness="0"
520522
IsDoubleTapEnabled="True"
523+
IsTabStop="True"
521524
ItemsSource="{x:Bind CollectionViewSource.View, Mode=OneWay}"
522525
PreviewKeyDown="FileList_PreviewKeyDown"
523526
ScrollViewer.IsHorizontalScrollChainingEnabled="False"

src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ protected override void HookEvents()
5959
ItemManipulationModel.ScrollIntoViewInvoked += ItemManipulationModel_ScrollIntoViewInvoked;
6060
ItemManipulationModel.RefreshItemThumbnailInvoked += ItemManipulationModel_RefreshItemThumbnail;
6161
ItemManipulationModel.RefreshItemsThumbnailInvoked += ItemManipulationModel_RefreshItemsThumbnail;
62-
6362
}
6463

6564
private void ItemManipulationModel_RefreshItemsThumbnail(object? sender, EventArgs e)
@@ -134,7 +133,10 @@ private void ItemManipulationModel_SelectAllItemsInvoked(object? sender, EventAr
134133

135134
private void ItemManipulationModel_FocusFileListInvoked(object? sender, EventArgs e)
136135
{
137-
FileList.Focus(FocusState.Programmatic);
136+
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
137+
var isFileListFocused = DependencyObjectHelpers.FindParent<ListViewBase>(focusedElement) == FileList;
138+
if (!isFileListFocused)
139+
FileList.Focus(FocusState.Programmatic);
138140
}
139141

140142
private void ZoomIn(object? sender, GroupOption option)
@@ -326,7 +328,7 @@ private void RenameTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
326328
private void RenameTextBox_LostFocus(object sender, RoutedEventArgs e)
327329
{
328330
// This check allows the user to use the text box context menu without ending the rename
329-
if ((FocusManager.GetFocusedElement() is AppBarButton or Popup))
331+
if ((FocusManager.GetFocusedElement(XamlRoot) is AppBarButton or Popup))
330332
return;
331333

332334
TextBox textBox = (TextBox)e.OriginalSource;
@@ -373,7 +375,7 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
373375
{
374376
var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
375377
var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
376-
var focusedElement = FocusManager.GetFocusedElement() as FrameworkElement;
378+
var focusedElement = FocusManager.GetFocusedElement(XamlRoot) as FrameworkElement;
377379
var isFooterFocused = focusedElement is HyperlinkButton;
378380

379381
if (e.Key == VirtualKey.Enter && !isFooterFocused && !e.KeyStatus.IsMenuKeyDown)
@@ -412,12 +414,12 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
412414
else if (e.KeyStatus.IsMenuKeyDown && (e.Key == VirtualKey.Left || e.Key == VirtualKey.Right || e.Key == VirtualKey.Up))
413415
{
414416
// Unfocus the GridView so keyboard shortcut can be handled
415-
NavToolbar?.Focus(FocusState.Pointer);
417+
this.Focus(FocusState.Pointer);
416418
}
417419
else if (e.KeyStatus.IsMenuKeyDown && shiftPressed && e.Key == VirtualKey.Add)
418420
{
419421
// Unfocus the ListView so keyboard shortcut can be handled (alt + shift + "+")
420-
NavToolbar?.Focus(FocusState.Pointer);
422+
this.Focus(FocusState.Pointer);
421423
}
422424
else if (e.Key == VirtualKey.Up || e.Key == VirtualKey.Down)
423425
{
@@ -438,7 +440,7 @@ protected override void Page_CharacterReceived(UIElement sender, CharacterReceiv
438440
if (ParentShellPageInstance.CurrentPageType == typeof(GridViewBrowser) && !IsRenamingItem)
439441
{
440442
// Don't block the various uses of enter key (key 13)
441-
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement();
443+
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
442444
if (InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Enter) == CoreVirtualKeyStates.Down
443445
|| focusedElement is Button
444446
|| focusedElement is TextBox

0 commit comments

Comments
 (0)