فهرست منبع

Fixed closing title bar with Esc (when using `rename` function), to properly re-allow keydown events.

Ruben 7 ماه پیش
والد
کامیت
a047644f15
2فایلهای تغییر یافته به همراه12 افزوده شده و 2 حذف شده
  1. 4 0
      src/PicView.Avalonia/Input/MainKeyboardShortcuts.cs
  2. 8 2
      src/PicView.Avalonia/Views/UC/EditableTitlebar.axaml.cs

+ 4 - 0
src/PicView.Avalonia/Input/MainKeyboardShortcuts.cs

@@ -186,6 +186,10 @@ public static class MainKeyboardShortcuts
         // Handle escape key
         // Handle escape key
         if (e.Key == Key.Escape)
         if (e.Key == Key.Escape)
         {
         {
+            if (UIHelper.GetMainView.DataContext as MainViewModel is { IsEditableTitlebarOpen: true })
+            {
+                return true;
+            }
             await FunctionsMapper.Close().ConfigureAwait(false);
             await FunctionsMapper.Close().ConfigureAwait(false);
             return true;
             return true;
         }
         }

+ 8 - 2
src/PicView.Avalonia/Views/UC/EditableTitlebar.axaml.cs

@@ -85,13 +85,19 @@ public partial class EditableTitlebar : UserControl
 
 
         if (!vm.IsEditableTitlebarOpen)
         if (!vm.IsEditableTitlebarOpen)
         {
         {
-            _ = MainKeyboardShortcuts.MainWindow_KeysDownAsync(e).ConfigureAwait(false);
+            // Don't pass the key to the main window
+            // Prevents keydown event being registered twice
+            e.Handled = true;  
             return;
             return;
         }
         }
-
+        
         if (e.Key is Key.Escape)
         if (e.Key is Key.Escape)
         {
         {
             CloseTitlebar();
             CloseTitlebar();
+            e.Handled = true;
+            var topLevel = TopLevel.GetTopLevel(this);
+            topLevel?.Focus();
+            return;
         }
         }
         MainKeyboardShortcuts.IsKeysEnabled = false;
         MainKeyboardShortcuts.IsKeysEnabled = false;
         base.OnKeyDown(e);
         base.OnKeyDown(e);