Displaying custom popups in RD mode that is sticky to the line

Hi @mik.kondratek,

For editors, it’s generally better to use offsets rather than component coordinates.

If you’re looking for a popup that sticks to a specific position and remains visible while scrolling, com.intellij.openapi.ui.popup.Balloon is a good option—it properly handles positioning even in RD mode.

Here’s an example of how you can create a popup that sticks to the caret position:

val position = VisualPosition(line, column) // Use LogicalPosition if needed
JBPopupFactory.getInstance()
  .createBalloonBuilder(content)
  .createBalloon()
  .show(object : PositionTracker<Balloon>(editor.contentComponent) {
    override fun recalculateLocation(balloon: Balloon): RelativePoint {
      // Convert stored position to editor coordinates
      return RelativePoint(editor.contentComponent, editor.visualPositionToXY(position))
    }
  }, Balloon.Position.above)
1 Like