Skip to content

Commit 789cb1d

Browse files
Feature: Disabled keyboard shortcuts when renaming items (#13118)
1 parent eca684f commit 789cb1d

File tree

2 files changed

+3
-66
lines changed

2 files changed

+3
-66
lines changed

src/Files.App/Data/Commands/HotKey/HotKeyHelpers.cs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,13 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Microsoft.UI.Input;
5-
using System.Collections.Generic;
6-
using System.Collections.Immutable;
75
using Windows.System;
86
using Windows.UI.Core;
97

108
namespace Files.App.Data.Commands
119
{
1210
internal static class HotKeyHelpers
1311
{
14-
private static readonly ImmutableArray<Keys> globalKeys = new List<Keys>
15-
{
16-
Keys.GoHome,
17-
Keys.GoBack,
18-
Keys.GoForward,
19-
Keys.Application,
20-
Keys.Favorites,
21-
Keys.Search,
22-
Keys.Refresh,
23-
Keys.Pause,
24-
Keys.Sleep,
25-
Keys.Print,
26-
Keys.F1,
27-
Keys.F2,
28-
Keys.F3,
29-
Keys.F4,
30-
Keys.F5,
31-
Keys.F6,
32-
Keys.F7,
33-
Keys.F8,
34-
Keys.F9,
35-
Keys.F10,
36-
Keys.F11,
37-
Keys.F12,
38-
Keys.F13,
39-
Keys.F14,
40-
Keys.F15,
41-
Keys.F16,
42-
Keys.F17,
43-
Keys.F18,
44-
Keys.F19,
45-
Keys.F20,
46-
Keys.F21,
47-
Keys.F22,
48-
Keys.F23,
49-
Keys.F24,
50-
}.ToImmutableArray();
51-
52-
private static readonly ImmutableArray<HotKey> textBoxHotKeys = new List<HotKey>
53-
{
54-
new HotKey(Keys.X, KeyModifiers.Ctrl), // Cut
55-
new HotKey(Keys.C, KeyModifiers.Ctrl), // Copy
56-
new HotKey(Keys.V, KeyModifiers.Ctrl), // Paste
57-
new HotKey(Keys.A, KeyModifiers.Ctrl), // Select all
58-
new HotKey(Keys.Z, KeyModifiers.Ctrl), // Cancel
59-
}.ToImmutableArray();
60-
61-
public static bool IsGlobalKey(this Keys key) => globalKeys.Contains(key);
62-
public static bool IsTextBoxHotKey(this HotKey hotKey) => textBoxHotKeys.Contains(hotKey);
63-
6412
public static KeyModifiers GetCurrentKeyModifiers()
6513
{
6614
var modifiers = VirtualKeyModifiers.None;

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@
44
using CommunityToolkit.WinUI.Helpers;
55
using CommunityToolkit.WinUI.UI;
66
using CommunityToolkit.WinUI.UI.Controls;
7-
using Files.App.Data.Items;
8-
using Files.App.Data.Models;
9-
using Files.App.UserControls;
107
using Files.App.UserControls.MultitaskingControl;
11-
using Files.Core.Extensions;
128
using Microsoft.Extensions.Logging;
139
using Microsoft.UI.Input;
1410
using Microsoft.UI.Xaml;
1511
using Microsoft.UI.Xaml.Controls;
1612
using Microsoft.UI.Xaml.Input;
1713
using Microsoft.UI.Xaml.Navigation;
18-
using Microsoft.Windows.ApplicationModel.Resources;
1914
using System.Runtime.CompilerServices;
2015
using Windows.ApplicationModel;
2116
using Windows.Services.Store;
@@ -220,14 +215,8 @@ protected override async void OnPreviewKeyDown(KeyRoutedEventArgs e)
220215
HotKey hotKey = new((Keys)e.Key, currentModifiers);
221216

222217
// A textbox takes precedence over certain hotkeys.
223-
bool isTextBox = e.OriginalSource is DependencyObject source && source.FindAscendantOrSelf<TextBox>() is not null;
224-
if (isTextBox)
225-
{
226-
if (hotKey.IsTextBoxHotKey())
227-
break;
228-
if (currentModifiers is KeyModifiers.None && !hotKey.Key.IsGlobalKey())
229-
break;
230-
}
218+
if (e.OriginalSource is DependencyObject source && source.FindAscendantOrSelf<TextBox>() is not null)
219+
break;
231220

232221
// Execute command for hotkey
233222
var command = Commands[hotKey];
@@ -273,7 +262,7 @@ private async void SidebarControl_SidebarItemDropped(object sender, SidebarItemD
273262
e.SignalEvent?.Set();
274263
}
275264

276-
private async void SidebarControl_SidebarItemPropertiesInvoked(object sender, SidebarItemPropertiesInvokedEventArgs e)
265+
private void SidebarControl_SidebarItemPropertiesInvoked(object sender, SidebarItemPropertiesInvokedEventArgs e)
277266
{
278267
if (e.InvokedItemDataContext is DriveItem)
279268
FilePropertiesHelpers.OpenPropertiesWindow(e.InvokedItemDataContext, SidebarAdaptiveViewModel.PaneHolder.ActivePane);

0 commit comments

Comments
 (0)