IJPL-161819 remove magic wand caret

GitOrigin-RevId: f89323e2548e0a5c45f733b4c3a87be6cfddb466
This commit is contained in:
Alexandr Trushev
2024-09-09 14:59:14 +02:00
committed by intellij-monorepo-bot
parent 4e0df68241
commit df4b25fc79
2 changed files with 6 additions and 76 deletions

View File

@@ -64,7 +64,6 @@ import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.EmptyIcon; import com.intellij.util.ui.EmptyIcon;
import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.accessibility.AccessibleContextUtil; import com.intellij.util.ui.accessibility.AccessibleContextUtil;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly; import org.jetbrains.annotations.TestOnly;
@@ -126,17 +125,6 @@ public final class IntentionHintComponent implements Disposable, ScrollAwareHint
DynamicPlugins.INSTANCE.onPluginUnload(this, () -> Disposer.dispose(this)); DynamicPlugins.INSTANCE.onPluginUnload(this, () -> Disposer.dispose(this));
} }
private IntentionHintComponent(@NotNull Project project,
@NotNull Editor editor,
@NotNull Icon icon) {
myEditor = editor;
myPopup = null;
myLightBulbPanel = new MagicWandPanel(project, editor, icon);
myComponentHint = new MyComponentHint(myLightBulbPanel, true);
EditorUtil.disposeWithEditor(myEditor, this);
DynamicPlugins.INSTANCE.onPluginUnload(this, () -> Disposer.dispose(this));
}
@RequiresEdt @RequiresEdt
public static @NotNull IntentionHintComponent showIntentionHint(@NotNull Project project, public static @NotNull IntentionHintComponent showIntentionHint(@NotNull Project project,
@NotNull PsiFile file, @NotNull PsiFile file,
@@ -184,16 +172,6 @@ public final class IntentionHintComponent implements Disposable, ScrollAwareHint
return component; return component;
} }
@ApiStatus.Experimental
@ApiStatus.Internal
public static @NotNull IntentionHintComponent showIntentionHint2(@NotNull Project project,
@NotNull Editor editor,
@NotNull Icon icon) {
IntentionHintComponent component = new IntentionHintComponent(project, editor, icon);
component.showIntentionHintImpl2();
return component;
}
public boolean isVisible() { public boolean isVisible() {
return myLightBulbPanel.isVisible(); return myLightBulbPanel.isVisible();
} }
@@ -271,20 +249,6 @@ public final class IntentionHintComponent implements Disposable, ScrollAwareHint
} }
} }
private void showIntentionHintImpl2() {
int offset = myEditor.getCaretModel().getOffset();
myComponentHint.setShouldDelay(false);
Point position = LightBulbUtil.getPosition2(myEditor);
QuestionAction action = new QuestionAction() {
@Override
public boolean execute() {
return false;
}
};
int flags = HintManager.UPDATE_BY_SCROLLING | HintManager.HIDE_IF_OUT_OF_EDITOR | HintManager.DONT_CONSUME_ESCAPE;
HintManagerImpl.showQuestionHint(myEditor, position, offset, offset, myComponentHint, flags, action, HintManager.ABOVE);
}
@TestOnly @TestOnly
public LightweightHint getComponentHint() { public LightweightHint getComponentHint() {
return myComponentHint; return myComponentHint;
@@ -369,17 +333,11 @@ public final class IntentionHintComponent implements Disposable, ScrollAwareHint
} }
private static final class MyComponentHint extends LightweightHint { private static final class MyComponentHint extends LightweightHint {
private final boolean isNotVisibleHint;
private boolean myVisible; private boolean myVisible;
private boolean myShouldDelay; private boolean myShouldDelay;
private MyComponentHint(JComponent component) { private MyComponentHint(JComponent component) {
this(component, false);
}
private MyComponentHint(JComponent component, boolean isNotVisibleHint) {
super(component); super(component);
this.isNotVisibleHint = isNotVisibleHint;
} }
@Override @Override
@@ -407,9 +365,6 @@ public final class IntentionHintComponent implements Disposable, ScrollAwareHint
@Override @Override
public boolean isVisible() { public boolean isVisible() {
if (isNotVisibleHint) {
return false;
}
return myVisible || super.isVisible(); return myVisible || super.isVisible();
} }
@@ -473,14 +428,6 @@ public final class IntentionHintComponent implements Disposable, ScrollAwareHint
: getPositionMultiLine(editor); : getPositionMultiLine(editor);
} }
private static Point getPosition2(Editor editor) {
VisualPosition vp = editor.getCaretModel().getPrimaryCaret().getVisualPosition();
vp = new VisualPosition(vp.getLine() > 0 ? vp.getLine() - 1 : vp.getLine(), vp.getColumn());
Point point = editor.visualPositionToXY(vp);
point = new Point(point.x-4, point.y+11);
return SwingUtilities.convertPoint(editor.getContentComponent(), point, getLayeredPane(editor));
}
private static @NotNull Point getPositionOneLine(Editor editor) { private static @NotNull Point getPositionOneLine(Editor editor) {
JComponent convertComponent = editor.getContentComponent(); JComponent convertComponent = editor.getContentComponent();
@@ -558,14 +505,14 @@ public final class IntentionHintComponent implements Disposable, ScrollAwareHint
} }
/** The light bulb icon, optionally surrounded by a border. */ /** The light bulb icon, optionally surrounded by a border. */
private class LightBulbPanel extends JPanel { private final class LightBulbPanel extends JPanel {
private static final Icon ourInactiveArrowIcon = IconManager.getInstance().createEmptyIcon(AllIcons.General.ArrowDown); private static final Icon ourInactiveArrowIcon = IconManager.getInstance().createEmptyIcon(AllIcons.General.ArrowDown);
private final RowIcon myHighlightedIcon; private final RowIcon myHighlightedIcon;
private final RowIcon myInactiveIcon; private final RowIcon myInactiveIcon;
private final JLabel myIconLabel; private final JLabel myIconLabel;
LightBulbPanel(@NotNull Project project, @Nullable PsiFile file, @NotNull Editor editor, @NotNull Icon smartTagIcon) { LightBulbPanel(@NotNull Project project, @NotNull PsiFile file, @NotNull Editor editor, @NotNull Icon smartTagIcon) {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
setOpaque(false); setOpaque(false);
@@ -575,9 +522,7 @@ public final class IntentionHintComponent implements Disposable, ScrollAwareHint
myIconLabel = new JLabel(myInactiveIcon); myIconLabel = new JLabel(myInactiveIcon);
myIconLabel.setOpaque(false); myIconLabel.setOpaque(false);
if (file != null) { myIconLabel.addMouseListener(new LightBulbMouseListener(project, file));
myIconLabel.addMouseListener(new LightBulbMouseListener(project, file));
}
AccessibleContextUtil.setName(myIconLabel, UIBundle.message("light.bulb.panel.accessible.name")); AccessibleContextUtil.setName(myIconLabel, UIBundle.message("light.bulb.panel.accessible.name"));
add(myIconLabel, BorderLayout.CENTER); add(myIconLabel, BorderLayout.CENTER);
@@ -595,14 +540,14 @@ public final class IntentionHintComponent implements Disposable, ScrollAwareHint
} }
@RequiresEdt @RequiresEdt
protected void onMouseExit() { private void onMouseExit() {
if (!myPopup.isVisible()) { if (!myPopup.isVisible()) {
myIconLabel.setIcon(myInactiveIcon); myIconLabel.setIcon(myInactiveIcon);
setBorder(LightBulbUtil.createInactiveBorder(myEditor)); setBorder(LightBulbUtil.createInactiveBorder(myEditor));
} }
} }
protected void onMouseEnter() { private void onMouseEnter() {
myIconLabel.setIcon(myHighlightedIcon); myIconLabel.setIcon(myHighlightedIcon);
setBorder(LightBulbUtil.createActiveBorder(myEditor)); setBorder(LightBulbUtil.createActiveBorder(myEditor));
@@ -614,20 +559,6 @@ public final class IntentionHintComponent implements Disposable, ScrollAwareHint
} }
} }
private final class MagicWandPanel extends LightBulbPanel {
MagicWandPanel(@NotNull Project project, @NotNull Editor editor, @NotNull Icon smartTagIcon) {
super(project, null, editor, smartTagIcon);
}
@Override
protected void onMouseExit() {
}
@Override
protected void onMouseEnter() {
}
}
// IDEA-313550: Intention light bulb border is calculated wrong // IDEA-313550: Intention light bulb border is calculated wrong
private final class LightBulbMouseListener extends MouseAdapter { private final class LightBulbMouseListener extends MouseAdapter {
private final @NotNull Project myProject; private final @NotNull Project myProject;

View File

@@ -642,8 +642,7 @@ public class HintManagerImpl extends HintManager {
showQuestionHint(editor, p, offset1, offset2, hint, action, constraint); showQuestionHint(editor, p, offset1, offset2, hint, action, constraint);
} }
@ApiStatus.Internal private static void showQuestionHint(final @NotNull Editor editor,
public static void showQuestionHint(final @NotNull Editor editor,
final @NotNull Point p, final @NotNull Point p,
final int offset1, final int offset1,
final int offset2, final int offset2,