Skip to content

Fix: Fixed issue where Alt-Up focused on the column header #10633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Files.App/UserControls/AddressToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void VisiblePath_KeyDown(object _, KeyRoutedEventArgs e)
}
private void VisiblePath_LostFocus(object _, RoutedEventArgs e)
{
var element = FocusManager.GetFocusedElement();
var element = FocusManager.GetFocusedElement(XamlRoot);
if (element is FlyoutBase or AppBarButton or Popup)
return;

Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Views/LayoutModes/ColumnViewBase.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,12 @@
DragItemsStarting="FileList_DragItemsStarting"
DragOver="ItemsLayout_DragOver"
Drop="ItemsLayout_Drop"
FocusVisualPrimaryThickness="0"
FocusVisualSecondaryThickness="0"
Holding="FileList_Holding"
IsDoubleTapEnabled="True"
IsRightTapEnabled="True"
IsTabStop="True"
ItemsSource="{x:Bind CollectionViewSource.View, Mode=OneWay}"
PreviewKeyDown="FileList_PreviewKeyDown"
PreviewKeyUp="FileList_PreviewKeyUp"
Expand Down
13 changes: 8 additions & 5 deletions src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ private void ItemManipulationModel_SelectAllItemsInvoked(object? sender, EventAr

private void ItemManipulationModel_FocusFileListInvoked(object? sender, EventArgs e)
{
FileList.Focus(FocusState.Programmatic);
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
var isFileListFocused = DependencyObjectHelpers.FindParent<ListViewBase>(focusedElement) == FileList;
if (!isFileListFocused)
FileList.Focus(FocusState.Programmatic);
}

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

// Don't block the various uses of enter key (key 13)
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement();
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);

if
(
Expand Down
4 changes: 4 additions & 0 deletions src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,17 @@
tui:ScrollViewerExtensions.EnableMiddleClickScrolling="{x:Bind IsMiddleClickToScrollEnabled, Mode=OneWay}"
x:FieldModifier="public"
AllowDrop="{x:Bind InstanceViewModel.IsPageTypeSearchResults, Converter={StaticResource BoolNegationConverter}, Mode=OneWay}"
AutomationProperties.AccessibilityView="Raw"
CanDragItems="True"
ContainerContentChanging="FileList_ContainerContentChanging"
DoubleTapped="FileList_DoubleTapped"
DragItemsStarting="FileList_DragItemsStarting"
DragOver="ItemsLayout_DragOver"
Drop="ItemsLayout_Drop"
FocusVisualPrimaryThickness="0"
FocusVisualSecondaryThickness="0"
IsDoubleTapEnabled="True"
IsTabStop="True"
ItemsSource="{x:Bind CollectionViewSource.View, Mode=OneWay}"
Loaded="FileList_Loaded"
PreviewKeyDown="FileList_PreviewKeyDown"
Expand Down
15 changes: 9 additions & 6 deletions src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ private void ItemManipulationModel_SelectAllItemsInvoked(object? sender, EventAr

private void ItemManipulationModel_FocusFileListInvoked(object? sender, EventArgs e)
{
FileList.Focus(FocusState.Programmatic);
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
var isFileListFocused = DependencyObjectHelpers.FindParent<ListViewBase>(focusedElement) == FileList;
if (!isFileListFocused)
FileList.Focus(FocusState.Programmatic);
}

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

Expand Down Expand Up @@ -460,12 +463,12 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
else if (e.KeyStatus.IsMenuKeyDown && (e.Key == VirtualKey.Left || e.Key == VirtualKey.Right || e.Key == VirtualKey.Up))
{
// Unfocus the GridView so keyboard shortcut can be handled
NavToolbar?.Focus(FocusState.Pointer);
this.Focus(FocusState.Pointer);
}
else if (e.KeyStatus.IsMenuKeyDown && shiftPressed && e.Key == VirtualKey.Add)
{
// Unfocus the ListView so keyboard shortcut can be handled (alt + shift + "+")
NavToolbar?.Focus(FocusState.Pointer);
this.Focus(FocusState.Pointer);
}
else if (e.Key == VirtualKey.Down)
{
Expand All @@ -491,7 +494,7 @@ protected override void Page_CharacterReceived(UIElement sender, CharacterReceiv
if (ParentShellPageInstance.CurrentPageType == typeof(DetailsLayoutBrowser) && !IsRenamingItem)
{
// Don't block the various uses of enter key (key 13)
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement();
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
var isHeaderFocused = DependencyObjectHelpers.FindParent<DataGridHeader>(focusedElement) is not null;
if (Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Enter) == CoreVirtualKeyStates.Down
|| (focusedElement is Button && !isHeaderFocused) // Allow jumpstring when header is focused
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Views/LayoutModes/GridViewBrowser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,10 @@
DragItemsStarting="FileList_DragItemsStarting"
DragOver="ItemsLayout_DragOver"
Drop="ItemsLayout_Drop"
FocusVisualPrimaryThickness="0"
FocusVisualSecondaryThickness="0"
IsDoubleTapEnabled="True"
IsTabStop="True"
ItemsSource="{x:Bind CollectionViewSource.View, Mode=OneWay}"
PreviewKeyDown="FileList_PreviewKeyDown"
ScrollViewer.IsHorizontalScrollChainingEnabled="False"
Expand Down
16 changes: 9 additions & 7 deletions src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ protected override void HookEvents()
ItemManipulationModel.ScrollIntoViewInvoked += ItemManipulationModel_ScrollIntoViewInvoked;
ItemManipulationModel.RefreshItemThumbnailInvoked += ItemManipulationModel_RefreshItemThumbnail;
ItemManipulationModel.RefreshItemsThumbnailInvoked += ItemManipulationModel_RefreshItemsThumbnail;

}

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

private void ItemManipulationModel_FocusFileListInvoked(object? sender, EventArgs e)
{
FileList.Focus(FocusState.Programmatic);
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
var isFileListFocused = DependencyObjectHelpers.FindParent<ListViewBase>(focusedElement) == FileList;
if (!isFileListFocused)
FileList.Focus(FocusState.Programmatic);
}

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

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

if (e.Key == VirtualKey.Enter && !isFooterFocused && !e.KeyStatus.IsMenuKeyDown)
Expand Down Expand Up @@ -412,12 +414,12 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
else if (e.KeyStatus.IsMenuKeyDown && (e.Key == VirtualKey.Left || e.Key == VirtualKey.Right || e.Key == VirtualKey.Up))
{
// Unfocus the GridView so keyboard shortcut can be handled
NavToolbar?.Focus(FocusState.Pointer);
this.Focus(FocusState.Pointer);
}
else if (e.KeyStatus.IsMenuKeyDown && shiftPressed && e.Key == VirtualKey.Add)
{
// Unfocus the ListView so keyboard shortcut can be handled (alt + shift + "+")
NavToolbar?.Focus(FocusState.Pointer);
this.Focus(FocusState.Pointer);
}
else if (e.Key == VirtualKey.Up || e.Key == VirtualKey.Down)
{
Expand All @@ -438,7 +440,7 @@ protected override void Page_CharacterReceived(UIElement sender, CharacterReceiv
if (ParentShellPageInstance.CurrentPageType == typeof(GridViewBrowser) && !IsRenamingItem)
{
// Don't block the various uses of enter key (key 13)
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement();
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
if (InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Enter) == CoreVirtualKeyStates.Down
|| focusedElement is Button
|| focusedElement is TextBox
Expand Down