Skip to content

Commit e9199bd

Browse files
authored
Feature: Added support for opening breadcrumb items using the space and enter keys (#16692)
1 parent 04c6fd7 commit e9199bd

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

src/Files.App/UserControls/PathBreadcrumb.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
IsItemClickEnabled="True"
137137
ItemTemplateSelector="{StaticResource PathBreadcrumbItemSelector}"
138138
ItemsSource="{x:Bind ViewModel.PathComponents, Mode=OneWay}"
139-
KeyDown="PathBoxItem_KeyDown"
139+
PreviewKeyDown="PathBoxItem_PreviewKeyDown"
140140
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
141141
ScrollViewer.HorizontalScrollMode="Enabled"
142142
ScrollViewer.VerticalScrollBarVisibility="Disabled"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ private void PathBoxItem_PointerPressed(object sender, PointerRoutedEventArgs e)
5555
ViewModel.PathBoxItem_PointerPressed(sender, e);
5656
}
5757

58-
private void PathBoxItem_KeyDown(object sender, KeyRoutedEventArgs e)
58+
private void PathBoxItem_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
5959
{
60-
ViewModel.PathBoxItem_KeyDown(sender, e);
60+
ViewModel.PathBoxItem_PreviewKeyDown(sender, e);
6161
}
6262
}
6363
}

src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,32 @@ await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
525525
});
526526
}
527527

528-
public void PathBoxItem_KeyDown(object sender, KeyRoutedEventArgs e)
528+
public void PathBoxItem_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
529529
{
530-
if (e.Key == Windows.System.VirtualKey.Down)
530+
switch (e.Key)
531531
{
532-
var item = e.OriginalSource as ListViewItem;
533-
var button = item?.FindDescendant<Button>();
534-
button?.Flyout.ShowAt(button);
535-
e.Handled = true;
532+
case Windows.System.VirtualKey.Down:
533+
{
534+
var item = e.OriginalSource as ListViewItem;
535+
var button = item?.FindDescendant<Button>();
536+
button?.Flyout.ShowAt(button);
537+
e.Handled = true;
538+
break;
539+
}
540+
case Windows.System.VirtualKey.Space:
541+
case Windows.System.VirtualKey.Enter:
542+
{
543+
var item = e.OriginalSource as ListViewItem;
544+
var path = (item?.Content as PathBoxItem)?.Path;
545+
if (path == PathControlDisplayText)
546+
return;
547+
ToolbarPathItemInvoked?.Invoke(this, new PathNavigationEventArgs()
548+
{
549+
ItemPath = path
550+
});
551+
e.Handled = true;
552+
break;
553+
}
536554
}
537555
}
538556

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,19 @@ private async Task OnPreviewKeyDownAsync(KeyRoutedEventArgs e)
235235
default:
236236
var currentModifiers = HotKeyHelpers.GetCurrentKeyModifiers();
237237
HotKey hotKey = new((Keys)e.Key, currentModifiers);
238+
var source = e.OriginalSource as DependencyObject;
238239

239240
// A textbox takes precedence over certain hotkeys.
240-
if (e.OriginalSource is DependencyObject source && source.FindAscendantOrSelf<TextBox>() is not null)
241+
if (source?.FindAscendantOrSelf<TextBox>() is not null)
241242
break;
242243

243244
// Execute command for hotkey
244245
var command = Commands[hotKey];
246+
247+
if (command.Code is CommandCodes.OpenItem && source?.FindAscendantOrSelf<PathBreadcrumb>() is not null)
248+
break;
249+
250+
245251
if (command.Code is not CommandCodes.None && keyReleased)
246252
{
247253
keyReleased = false;

0 commit comments

Comments
 (0)