package com.intellij.ide.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.ui.awt.RelativePoint;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;

/**
 * @author Vladimir Kondratyev
 */
public class ShowPopupMenuAction extends AnAction {
  public ShowPopupMenuAction() {
    setEnabledInModalContext(true);
  }

  public void actionPerformed(AnActionEvent e) {
    final RelativePoint relPoint = JBPopupFactory.getInstance().guessBestPopupLocation(e.getDataContext());

    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focusOwner = focusManager.getFocusOwner();

    Point popupMenuPoint = relPoint.getPoint(focusOwner);

    focusOwner.dispatchEvent(
      new MouseEvent(
        focusOwner,
        MouseEvent.MOUSE_PRESSED,
        System.currentTimeMillis(), 0,
        popupMenuPoint.x,
        Math.max(0, popupMenuPoint.y - 1), //To avoid cursor jump to the line below. http://www.jetbrains.net/jira/browse/IDEADEV-10644
        1,
        true
      )
    );
  }

  public void update(AnActionEvent e) {
    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    e.getPresentation().setEnabled(focusManager.getFocusOwner() instanceof JComponent);
  }
}
@@ -135,16 +135,118 @@
 nEvent;%0A
+import com.intellij.openapi.actionSystem.PlatformDataKeys;%0Aimport com.intellij.openapi.editor.Editor;%0A
 import c
@@ -940,24 +940,299 @@
 cusOwner);%0A%0A
+    final Editor editor = e.getData(PlatformDataKeys.EDITOR);%0A    int coord = editor != null%0A                ? Math.max(0, popupMenuPoint.y - 1) //To avoid cursor jump to the line below. http://www.jetbrains.net/jira/browse/IDEADEV-10644%0A                : popupMenuPoint.y;%0A%0A
     focusOwn
@@ -1245,24 +1245,24 @@
 patchEvent(%0A
-
       new Mo
@@ -1402,135 +1402,14 @@
     
-Math.max(0, popupMenuPoint.y - 1), //To avoid cursor jump to the line below. http://www.jetbrains.net/jira/browse/IDEADEV-10644
+coord,
 %0A   

apply popup menu coordinate hack only in editor (IDEADEV-29565)