Skip to content

Commit

Permalink
Fix rename hijacking keyboard and close rename when clicking Esc
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Jan 2, 2025
1 parent 54bce0d commit 5186943
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/PicView.Avalonia/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
15 changes: 15 additions & 0 deletions src/PicView.Avalonia/Views/UC/EditableTitlebar.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public EditableTitlebar()
LostFocus += OnLostFocus;
PointerEntered += OnPointerEntered;
PointerPressed += OnPointerPressed;
TextBox.LostFocus += OnLostFocus;
}

private void OnPointerPressed(object? sender, PointerPressedEventArgs e)
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 5186943

Please sign in to comment.