From cf7c865432282640b1c8314c43a0bd54e6f5f6c9 Mon Sep 17 00:00:00 2001 From: reuk Date: Fri, 12 May 2023 18:48:29 +0100 Subject: [PATCH] NSViewComponentPeer: Ensure inner views that receive key equivalents reset keyDown state correctly --- .../native/juce_NSViewComponentPeer_mac.mm | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm b/modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm index 5d79e41dd3..eef43d6f26 100644 --- a/modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm +++ b/modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm @@ -2235,8 +2235,33 @@ struct JuceNSViewClass : public NSViewComponentPeerWrapper> addMethod (@selector (performKeyEquivalent:), [] (id self, SEL s, NSEvent* ev) -> BOOL { if (auto* owner = getOwner (self)) + { + const auto ref = owner->safeComponent; + if (owner->sendEventToInputContextOrComponent (ev)) + { + if (ref == nullptr) + return YES; + + const auto isFirstResponder = [&] + { + if (auto* v = owner->view) + if (auto* w = v.window) + return w.firstResponder == self; + + return false; + }(); + + // If the view isn't the first responder, but the view has successfully + // performed the key equivalent, then the key event must have been passed down + // the view hierarchy to this point. In that case, the view won't be sent a + // matching keyUp event, so we simulate it here. + if (! isFirstResponder) + owner->redirectKeyUp (ev); + return YES; + } + } return sendSuperclassMessage (self, s, ev); });