leave inplace popup on the old place when best location become invisible (IDEA-89827)

This commit is contained in:
Anna Kozlova
2012-08-07 22:31:35 +04:00
parent bc85f645b0
commit 0c56a5e7e4
3 changed files with 974 additions and 954 deletions
@@ -36,10 +36,7 @@ import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.command.impl.FinishMarkAction;
import com.intellij.openapi.command.impl.StartMarkAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.impl.EditorImpl;
@@ -699,10 +696,15 @@ public abstract class InplaceRefactoring {
}
});
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
myBalloon.show(new PositionTracker<Balloon>(myEditor.getContentComponent()) {
@Override
public RelativePoint recalculateLocation(Balloon object) {
final RelativePoint target = JBPopupFactory.getInstance().guessBestPopupLocation(myEditor);
if (myTarget != null && !popupFactory.isBestPopupLocationVisible(myEditor)) {
return myTarget;
}
final RelativePoint target = popupFactory.guessBestPopupLocation(myEditor);
if (target == null) return myTarget;
final Point screenPoint = target.getScreenPoint();
int y = screenPoint.y;
if (target.getPoint().getY() > myEditor.getLineHeight() + myBalloon.getPreferredSize().getHeight()) {
@@ -247,6 +247,13 @@ public abstract class JBPopupFactory {
*/
public abstract RelativePoint guessBestPopupLocation(Editor editor);
/**
* @param editor the editor over which the popup is shown.
* @return true if popup location is located in visible area
* false if center would be suggested instead
*/
public abstract boolean isBestPopupLocationVisible(Editor editor);
public abstract Point getCenterOf(JComponent container, JComponent content);
@Nullable
File diff suppressed because it is too large Load Diff