|
6 | 6 | using Files.App.Helpers.ContextFlyouts;
|
7 | 7 | using Files.App.UserControls.Menus;
|
8 | 8 | using Files.App.ViewModels.Layouts;
|
| 9 | +using Microsoft.UI.Input; |
9 | 10 | using Microsoft.UI.Xaml;
|
10 | 11 | using Microsoft.UI.Xaml.Controls;
|
11 | 12 | using Microsoft.UI.Xaml.Controls.Primitives;
|
|
23 | 24 | using Windows.Foundation.Collections;
|
24 | 25 | using Windows.Storage;
|
25 | 26 | using Windows.System;
|
| 27 | +using Windows.UI.Core; |
26 | 28 | using static Files.App.Helpers.PathNormalization;
|
27 | 29 | using DispatcherQueueTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
|
28 | 30 | using SortDirection = Files.App.Data.Enums.SortDirection;
|
@@ -401,7 +403,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
|
401 | 403 | base.OnNavigatedTo(e);
|
402 | 404 |
|
403 | 405 | // Add item jumping handler
|
404 |
| - CharacterReceived += Page_CharacterReceived; |
| 406 | + PreviewKeyDown += Page_PreviewKeyDown; ; |
405 | 407 |
|
406 | 408 | navigationArguments = (NavigationArguments)e.Parameter;
|
407 | 409 | ParentShellPageInstance = navigationArguments.AssociatedTabInstance;
|
@@ -565,7 +567,7 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
|
565 | 567 | base.OnNavigatingFrom(e);
|
566 | 568 |
|
567 | 569 | // Remove item jumping handler
|
568 |
| - CharacterReceived -= Page_CharacterReceived; |
| 570 | + PreviewKeyDown -= Page_PreviewKeyDown; |
569 | 571 | FolderSettings!.LayoutModeChangeRequested -= BaseFolderSettings_LayoutModeChangeRequested;
|
570 | 572 | FolderSettings.GroupOptionPreferenceUpdated -= FolderSettings_GroupOptionPreferenceUpdated;
|
571 | 573 | FolderSettings.GroupDirectionPreferenceUpdated -= FolderSettings_GroupDirectionPreferenceUpdated;
|
@@ -996,12 +998,39 @@ private void RemoveOverflow(CommandBarFlyout contextMenuFlyout)
|
996 | 998 | overflowSeparator.Visibility = Visibility.Collapsed;
|
997 | 999 | }
|
998 | 1000 |
|
999 |
| - protected virtual void Page_CharacterReceived(UIElement sender, CharacterReceivedRoutedEventArgs args) |
| 1001 | + protected virtual void Page_PreviewKeyDown(object sender, KeyRoutedEventArgs e) |
1000 | 1002 | {
|
1001 |
| - if (ParentShellPageInstance!.IsCurrentInstance) |
| 1003 | + var key = e.Key; |
| 1004 | + var filter = ParentShellPageInstance?.ShellViewModel.FilesAndFoldersFilter; |
| 1005 | + |
| 1006 | + if (ParentShellPageInstance?.IsCurrentInstance != true) |
| 1007 | + return; |
| 1008 | + |
| 1009 | + // OemMinus usually maps to virtual key code 189 |
| 1010 | + bool isOemMinus = (int)key == 189; |
| 1011 | + bool isShiftDown = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down); |
| 1012 | + |
| 1013 | + char? keyChar = key switch |
| 1014 | + { |
| 1015 | + >= VirtualKey.A and <= VirtualKey.Z => (char)('A' + (key - VirtualKey.A)), |
| 1016 | + >= VirtualKey.Number0 and <= VirtualKey.Number9 => (char)('0' + (key - VirtualKey.Number0)), |
| 1017 | + _ => isOemMinus ? (isShiftDown ? '_' : '-') : null |
| 1018 | + }; |
| 1019 | + |
| 1020 | + if (keyChar.HasValue && |
| 1021 | + !Path.GetInvalidFileNameChars().Contains(char.ToLowerInvariant(keyChar.Value))) |
| 1022 | + { |
| 1023 | + string ch = keyChar.Value.ToString().ToLowerInvariant(); |
| 1024 | + ParentShellPageInstance.ShellViewModel.FilesAndFoldersFilter += ch; |
| 1025 | + JumpString += ch; |
| 1026 | + } |
| 1027 | + else if (key == VirtualKey.Space && !string.IsNullOrEmpty(filter)) |
| 1028 | + { |
| 1029 | + ParentShellPageInstance.ShellViewModel.FilesAndFoldersFilter += " "; |
| 1030 | + } |
| 1031 | + else if (key == VirtualKey.Back && !string.IsNullOrEmpty(filter)) |
1002 | 1032 | {
|
1003 |
| - char letter = args.Character; |
1004 |
| - JumpString += letter.ToString().ToLowerInvariant(); |
| 1033 | + ParentShellPageInstance.ShellViewModel.FilesAndFoldersFilter = filter[..^1]; |
1005 | 1034 | }
|
1006 | 1035 | }
|
1007 | 1036 |
|
|
0 commit comments