diff --git a/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/SearchEverywhereManagerImpl.java b/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/SearchEverywhereManagerImpl.java index bfa08b99f3a0..0d4ea4275271 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/SearchEverywhereManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/SearchEverywhereManagerImpl.java @@ -11,15 +11,18 @@ import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.DimensionService; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.wm.WindowManager; import com.intellij.ui.SearchTextField; +import com.intellij.ui.awt.RelativePoint; import com.intellij.util.ui.JBInsets; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.util.*; import java.util.List; +import java.util.*; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -136,18 +139,26 @@ public class SearchEverywhereManagerImpl implements SearchEverywhereManager { private void calcPositionAndShow(Project project, JBPopup balloon) { Point savedLocation = DimensionService.getInstance().getLocation(LOCATION_SETTINGS_KEY, project); + //for first show and short mode popup should be shifted to the top screen half + if (savedLocation == null && mySearchEverywhereUI.getViewType() == SearchEverywhereUI.ViewType.SHORT) { + Window window = project != null + ? WindowManager.getInstance().suggestParentWindow(project) + : KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); + Component parent = UIUtil.findUltimateParent(window); + + if (parent != null) { + Dimension balloonSize = balloon.getContent().getPreferredSize(); + RelativePoint showPoint = new RelativePoint(parent, new Point((parent.getSize().width - balloonSize.width) / 2, parent.getHeight() / 4 - balloonSize.height / 2)); + balloon.show(showPoint); + return; + } + } + if (project != null) { balloon.showCenteredInCurrentWindow(project); } else { balloon.showInFocusCenter(); } - - //for first show and short mode popup should be shifted to the top screen half - if (savedLocation == null && mySearchEverywhereUI.getViewType() == SearchEverywhereUI.ViewType.SHORT) { - Point location = balloon.getLocationOnScreen(); - location.y /= 2; - balloon.setLocation(location); - } } @Override