Skip to content

Commit

Permalink
Feature: Only open single tab if user holds down ctrl + t (#11743)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrariofilippo authored Mar 16, 2023
1 parent 9c70d8d commit 0a95fce
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public MainPageViewModel ViewModel
/// </summary>
private bool draggingPreviewPane;

private bool keyReleased = true;

public SidebarViewModel SidebarAdaptiveViewModel = new SidebarViewModel();

public OngoingTasksViewModel OngoingTasksViewModel => App.OngoingTasksViewModel;
Expand Down Expand Up @@ -235,20 +237,19 @@ protected override async void OnPreviewKeyDown(KeyRoutedEventArgs e)
default:
// break for natives hotkeys in textbox (cut/copy/paste/selectAll/cancel)
bool isTextBox = e.OriginalSource is DependencyObject source && source.FindAscendantOrSelf<TextBox>() is not null;
if (isTextBox)
if (isTextBox &&
currentModifiers is VirtualKeyModifiers.Control &&
e.Key is VirtualKey.X or VirtualKey.C or VirtualKey.V or VirtualKey.A or VirtualKey.Z)
{
if (currentModifiers is VirtualKeyModifiers.Control &&
e.Key is VirtualKey.X or VirtualKey.C or VirtualKey.V or VirtualKey.A or VirtualKey.Z)
{
break;
}
break;
}

// execute command for hotkey
var hotKey = new HotKey(e.Key, currentModifiers);
var command = Commands[hotKey];
if (command.Code is not CommandCodes.None)
if (command.Code is not CommandCodes.None && keyReleased)
{
keyReleased = false;
e.Handled = command.IsExecutable;
await command.ExecuteAsync();
}
Expand All @@ -261,6 +262,10 @@ protected override void OnPreviewKeyUp(KeyRoutedEventArgs e)

switch (e.Key)
{
case VirtualKey.LeftWindows:
case VirtualKey.RightWindows:
currentModifiers |= VirtualKeyModifiers.Windows;
break;
case VirtualKey.Menu:
currentModifiers &= ~VirtualKeyModifiers.Menu;
break;
Expand All @@ -270,6 +275,9 @@ protected override void OnPreviewKeyUp(KeyRoutedEventArgs e)
case VirtualKey.Shift:
currentModifiers &= ~VirtualKeyModifiers.Shift;
break;
default:
keyReleased = true;
break;
}
}

Expand Down

0 comments on commit 0a95fce

Please sign in to comment.