From 973ed0d00ec52cada331f2b975edef865e7e66ac Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Fri, 7 Dec 2018 17:33:18 +0300 Subject: [PATCH] IDEA-198297 Quick Documentation popup is sometimes placed off screen prevent quick doc popup from splitting between screens - update fix to avoid NPE on showing popup --- .../src/com/intellij/ui/popup/AbstractPopup.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java index d9c1127900f4..4d4dc13fedee 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -509,7 +509,7 @@ public class AbstractPopup implements JBPopup { RelativePoint location = JBPopupFactory.getInstance().guessBestPopupLocation(dataContext); if (myLocateWithinScreen) { Point screenPoint = location.getScreenPoint(); - Rectangle rectangle = new Rectangle(screenPoint, getSize()); + Rectangle rectangle = new Rectangle(screenPoint, getSizeForPositioning()); Rectangle screen = ScreenUtil.getScreenRectangle(screenPoint); ScreenUtil.moveToFit(rectangle, screen, null); location = new RelativePoint(rectangle.getLocation()).getPointOn(location.getComponent()); @@ -517,6 +517,17 @@ public class AbstractPopup implements JBPopup { return location; } + private Dimension getSizeForPositioning() { + Dimension size = getSize(); + if (size == null && myDimensionServiceKey != null) { + size = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject); + } + if (size == null) { + size = myContent.getPreferredSize(); + } + return size; + } + @Override public void showInBestPositionFor(@NotNull Editor editor) { assert editor.getComponent().isShowing() : "Editor must be showing on the screen";