From 8dce6c0b6710d0a426cd16ffd21886145e90fd3f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 2 Mar 2024 15:27:47 +0000 Subject: [PATCH] Don't steal command-keys from a wxGrid. It's unlikely to win you friends. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17229 (cherry picked from commit 1082930c347f4f880aa0d2add1d8bf6fdcdacf79) --- common/tool/action_menu.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/common/tool/action_menu.cpp b/common/tool/action_menu.cpp index 51abdf5a39..728434fa01 100644 --- a/common/tool/action_menu.cpp +++ b/common/tool/action_menu.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include using namespace std::placeholders; @@ -436,7 +437,8 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent ) // events first. if( dynamic_cast( focus ) || dynamic_cast( focus ) - || dynamic_cast( focus ) ) + || dynamic_cast( focus ) + || dynamic_cast( focus ) ) { // Original key event has been lost, so we have to re-create it from the menu's // wxAcceleratorEntry. @@ -451,7 +453,7 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent ) keyEvent.m_shiftDown = ( acceleratorKey->GetFlags() & wxMOD_SHIFT ) > 0; keyEvent.m_altDown = ( acceleratorKey->GetFlags() & wxMOD_ALT ) > 0; - if( auto ctrl = dynamic_cast( focus ) ) + if( wxTextEntry* ctrl = dynamic_cast( focus ) ) TEXTENTRY_TRICKS::OnCharHook( ctrl, keyEvent ); else focus->HandleWindowEvent( keyEvent ); @@ -462,10 +464,14 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent ) focus->HandleWindowEvent( keyEvent ); } - // If the event was used as KEY event (not skipped) by the focused window, - // just finish. - // Otherwise this is actually a wxEVT_COMMAND_MENU_SELECTED, or the - // focused window is read only + // Don't bubble-up dangerous actions; the target may be behind a modeless dialog. + // Cf. https://gitlab.com/kicad/code/kicad/-/issues/17229 + if( keyEvent.GetKeyCode() == WXK_BACK || keyEvent.GetKeyCode() == WXK_DELETE ) + return; + + // If the event was used as a KEY event (not skipped) by the focused window, + // just finish. Otherwise this is actually a wxEVT_COMMAND_MENU_SELECTED (or the + // focused window is read only). if( !keyEvent.GetSkipped() ) return; }