From 43daadda0866d4c99f9be4f449592a8cd03e90e2 Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Fri, 25 Dec 2009 17:07:37 +0300 Subject: [PATCH] IDEADEV-42117 Focus does not come to menu --- .../util/gotoByName/ChooseByNamePopup.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNamePopup.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNamePopup.java index b21bde53ca04..090060e4f785 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNamePopup.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNamePopup.java @@ -21,6 +21,7 @@ import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.openapi.wm.ex.LayoutFocusTraversalPolicyExt; import com.intellij.psi.PsiElement; import com.intellij.psi.statistics.StatisticsInfo; @@ -161,17 +162,21 @@ public class ChooseByNamePopup extends ChooseByNameBase implements ChooseByNameP private void cleanupUI() { JLayeredPane layeredPane = null; try { - // Return focus back to the previous focused component if we need to do it and - // previous focused componen is showing. - if ( - myPreviouslyFocusedComponent instanceof JComponent && - myPreviouslyFocusedComponent.isShowing() - ){ - final JComponent _component = (JComponent)myPreviouslyFocusedComponent; - LayoutFocusTraversalPolicyExt.setOverridenDefaultComponent(_component); - } - if (myPreviouslyFocusedComponent != null) { - myPreviouslyFocusedComponent.requestFocus(); + // check if the currently focused component was changed already, so we could leave focus intact + final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); + if (SwingUtilities.isDescendingFrom(owner, myTextField)) { + // Return focus back to the previous focused component if we need to do it and + // previous focused componen is showing. + if ( + myPreviouslyFocusedComponent instanceof JComponent && + myPreviouslyFocusedComponent.isShowing() + ){ + final JComponent _component = (JComponent)myPreviouslyFocusedComponent; + LayoutFocusTraversalPolicyExt.setOverridenDefaultComponent(_component); + } + if (myPreviouslyFocusedComponent != null) { + myPreviouslyFocusedComponent.requestFocus(); + } } final JRootPane rootPane = myTextFieldPanel.getRootPane();