Hide balloon on mouse exit

已回答

Hi

I have an inlay which I am adding to the end of some line in the editor.

I would like to display a balloon or tooltip when the user hovers over this inlay and hide the balloon when the mouse exits the ballon and inlay (i.e. mouse is not hovering either).

I added a mouse listener to the editor so when the mouse is over my inlay I display a balloon. How can I make this balloon disappear on mouse exit? I can probably implement this myself with the mouse listener, but surely there's a better way?

This is how I'm creating the balloon:

this.balloon = JBPopupFactory.getInstance()
.createHtmlTextBalloonBuilder(hoverBinaryResponse.getMessage(),MessageType.INFO, null)
.setDisposable(inlay)
.createBalloon();
Disposer.register(this.balloon, () -> this.balloon = null);
this.balloon.show(new RelativePoint(mouseEvent),Balloon.Position.atRight);

I tried using an IdeToolTip but that didn't work either (not sure I used the right components):

final JLabel label = new JLabel("Tooltip");
final JEditorPane pane = initPane("tooltip text",
new HintHint(mouseEvent).setAwtTooltip(true),
null);
final Wrapper wrapper = new Wrapper(pane);
this.ideTooltip = new IdeTooltip(editor.getComponent().getComponentAt(mouseEvent.getPoint()),
mouseEvent.getPoint(),
wrapper,
label)
.setLayer(Balloon.Layer.top);
IdeTooltipManager.getInstance().show(this.ideTooltip, true);

Thanks

Shai

0

I'm not sure. I'll take a look at it.

Thanks.

0

I tried:

HintManager.getInstance().showInformationHint(editor, text)

but the popup still closes only when I click outside it. I also tried:

HintManager.getInstance().showErrorHint

with all sorts of hide flags but nothing gives the required behaviour. What am I missing?

Thanks

0

Did you try com.intellij.codeInsight.hint.HintManager#HIDE_BY_MOUSEOVER

0

Hi Yann

I have, and as the name suggests, the popup is closed whenever I move my cursor over it. I need the exact opposite behavior.

My popup contains links, so I want it to stay open when the cursor hovers over it and disappear when the cursor exits the popup.

It looks like LineTooltipRenderer uses a MouseMovementTracker with some logic to achieve this. Obviously I prefer not to copy this whole logic and use some built in API. This sounds like a pretty standard use case to me so I was hoping there's already something I can use?

To make things worse, our plugin currently supports version 2018 and I would prefer not to break this.

0

Unfortunately there's no ready-made API for your use-case. Indeed EditorMouseHoverPopupManager and MouseMovementTracker can be used as building/blocks inspirations in your plugin

0

I see.

Thanks very much for your help.

Would you guys consider adding such behavior (e.g. HintManager#HIDE_BY_MOUSEEXIT)? Should I submit a feature request somewhere?

0

请先登录再写评论。