Переглянути джерело

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

Ruben 7 місяців тому
батько
коміт
a047644f15

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

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

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

@@ -85,13 +85,19 @@ public partial class EditableTitlebar : UserControl
 
         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;
         }
-
+        
         if (e.Key is Key.Escape)
         {
             CloseTitlebar();
+            e.Handled = true;
+            var topLevel = TopLevel.GetTopLevel(this);
+            topLevel?.Focus();
+            return;
         }
         MainKeyboardShortcuts.IsKeysEnabled = false;
         base.OnKeyDown(e);