From 33dd896ab2f15003b993d3c19e49a0a87b9e7e05 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 22 Jan 2021 10:15:27 +0000 Subject: [PATCH] Ensure that keyboard focus is always given away when components are made invisible --- modules/juce_gui_basics/components/juce_Component.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 78843e0cb9..006d3f5803 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -489,7 +489,7 @@ Component::~Component() if (parentComponent != nullptr) parentComponent->removeChildComponent (parentComponent->childComponentList.indexOf (this), true, false); - else if (currentlyFocusedComponent == this || isParentOf (currentlyFocusedComponent)) + else if (hasKeyboardFocus (true)) giveAwayFocus (currentlyFocusedComponent != this); if (flags.hasHeavyweightPeerFlag) @@ -546,11 +546,12 @@ void Component::setVisible (bool shouldBeVisible) { ComponentHelpers::releaseAllCachedImageResources (*this); - if (currentlyFocusedComponent == this || isParentOf (currentlyFocusedComponent)) + if (hasKeyboardFocus (true)) { if (parentComponent != nullptr) parentComponent->grabKeyboardFocus(); - else + + if (hasKeyboardFocus (true)) giveAwayFocus (true); } }