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
This commit is contained in:
Dmitry Batrak
2018-12-07 17:35:28 +03:00
parent 9e43d8b507
commit 973ed0d00e
@@ -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";