From e224f59ea75662e82e02618e2a0802cd27b8cff0 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 27 Nov 2024 20:21:01 +0800 Subject: [PATCH] enhance: clear unhandled key modifer before running command (#748) --- src/Views/Launcher.axaml.cs | 5 +++++ src/Views/RepositoryToolbar.axaml.cs | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Views/Launcher.axaml.cs b/src/Views/Launcher.axaml.cs index 29d90e09..4137579d 100644 --- a/src/Views/Launcher.axaml.cs +++ b/src/Views/Launcher.axaml.cs @@ -72,6 +72,11 @@ namespace SourceGit.Views return _unhandledModifiers.HasFlag(modifier); } + public void ClearKeyModifier() + { + _unhandledModifiers = KeyModifiers.None; + } + protected override void OnOpened(EventArgs e) { base.OnOpened(e); diff --git a/src/Views/RepositoryToolbar.axaml.cs b/src/Views/RepositoryToolbar.axaml.cs index afc8ac5a..1d9d634b 100644 --- a/src/Views/RepositoryToolbar.axaml.cs +++ b/src/Views/RepositoryToolbar.axaml.cs @@ -53,6 +53,7 @@ namespace SourceGit.Views if (!startDirectly && OperatingSystem.IsMacOS()) startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta); + launcher.ClearKeyModifier(); repo.Fetch(startDirectly); e.Handled = true; } @@ -67,6 +68,7 @@ namespace SourceGit.Views if (!startDirectly && OperatingSystem.IsMacOS()) startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta); + launcher.ClearKeyModifier(); repo.Pull(startDirectly); e.Handled = true; } @@ -81,6 +83,7 @@ namespace SourceGit.Views if (!startDirectly && OperatingSystem.IsMacOS()) startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta); + launcher.ClearKeyModifier(); repo.Push(startDirectly); e.Handled = true; } @@ -89,8 +92,16 @@ namespace SourceGit.Views private void StashAll(object _, RoutedEventArgs e) { var launcher = this.FindAncestorOfType(); - (DataContext as ViewModels.Repository)?.StashAll(launcher?.HasKeyModifier(KeyModifiers.Control) ?? false); - e.Handled = true; + if (launcher is not null && DataContext is ViewModels.Repository repo) + { + var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control); + if (!startDirectly && OperatingSystem.IsMacOS()) + startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta); + + launcher.ClearKeyModifier(); + repo.StashAll(startDirectly); + e.Handled = true; + } } private void OpenGitFlowMenu(object sender, RoutedEventArgs e)