From 518694311483f442f1ea681d01cceab5ca42f5bb Mon Sep 17 00:00:00 2001 From: Ruben Date: Thu, 2 Jan 2025 15:16:41 +0100 Subject: [PATCH] Fix rename hijacking keyboard and close rename when clicking `Esc` --- src/PicView.Avalonia/Views/MainView.axaml.cs | 11 ++++++++--- .../Views/UC/EditableTitlebar.axaml.cs | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/PicView.Avalonia/Views/MainView.axaml.cs b/src/PicView.Avalonia/Views/MainView.axaml.cs index e487d0238..1bc3c2e90 100644 --- a/src/PicView.Avalonia/Views/MainView.axaml.cs +++ b/src/PicView.Avalonia/Views/MainView.axaml.cs @@ -69,13 +69,18 @@ private void CloseTitlebarIfOpen(object? sender, EventArgs e) { 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(); } diff --git a/src/PicView.Avalonia/Views/UC/EditableTitlebar.axaml.cs b/src/PicView.Avalonia/Views/UC/EditableTitlebar.axaml.cs index 7c3dc2c09..df615976a 100644 --- a/src/PicView.Avalonia/Views/UC/EditableTitlebar.axaml.cs +++ b/src/PicView.Avalonia/Views/UC/EditableTitlebar.axaml.cs @@ -20,6 +20,7 @@ public EditableTitlebar() LostFocus += OnLostFocus; PointerEntered += OnPointerEntered; PointerPressed += OnPointerPressed; + TextBox.LostFocus += OnLostFocus; } private void OnPointerPressed(object? sender, PointerPressedEventArgs e) @@ -78,6 +79,20 @@ public void CloseTitlebar() 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); }