Browse Source

Fix rename hijacking keyboard and close rename when clicking `Esc`

Ruben 9 tháng trước cách đây
mục cha
commit
5186943114

+ 8 - 3
src/PicView.Avalonia/Views/MainView.axaml.cs

@@ -69,13 +69,18 @@ public partial class MainView : UserControl
         {
             return;
         }
-        if (vm.IsEditableTitlebarOpen)
+
+        if (!vm.IsEditableTitlebarOpen)
         {
-            vm.IsEditableTitlebarOpen = false;
+            return;
         }
+
+        vm.IsEditableTitlebarOpen = false;
+        MainKeyboardShortcuts.IsKeysEnabled = true;
+        Focus();
     }
     
-    private void HandleLostFocus(object? sender, EventArgs e)
+    private static void HandleLostFocus(object? sender, EventArgs e)
     {
         DragAndDropHelper.RemoveDragDropView();
     }

+ 15 - 0
src/PicView.Avalonia/Views/UC/EditableTitlebar.axaml.cs

@@ -20,6 +20,7 @@ public partial class EditableTitlebar : UserControl
         LostFocus += OnLostFocus;
         PointerEntered += OnPointerEntered;
         PointerPressed += OnPointerPressed;
+        TextBox.LostFocus += OnLostFocus;
     }
 
     private void OnPointerPressed(object? sender, PointerPressedEventArgs e)
@@ -78,6 +79,20 @@ public partial class EditableTitlebar : UserControl
     
     protected override void OnKeyDown(KeyEventArgs e)
     {
+        if (DataContext is not MainViewModel vm)
+        {
+            return;
+        }
+
+        if (!vm.IsEditableTitlebarOpen)
+        {
+            return;
+        }
+
+        if (e.Key is Key.Escape)
+        {
+            CloseTitlebar();
+        }
         MainKeyboardShortcuts.IsKeysEnabled = false;
         base.OnKeyDown(e);
     }