diff --git a/platform/platform-api/src/com/intellij/ide/HelpTooltip.java b/platform/platform-api/src/com/intellij/ide/HelpTooltip.java index 002dc87a92af..ac14a5132274 100644 --- a/platform/platform-api/src/com/intellij/ide/HelpTooltip.java +++ b/platform/platform-api/src/com/intellij/ide/HelpTooltip.java @@ -36,6 +36,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Map; import java.util.function.BooleanSupplier; +import java.util.regex.Pattern; /** * Standard implementation of help context tooltip. @@ -110,6 +111,7 @@ public class HelpTooltip { private static final String DOTS = "..."; private static final String PARAGRAPH_SPLITTER = "

"; + private static final Pattern HTML_TAG = Pattern.compile("|
"); private static final String TOOLTIP_PROPERTY = "JComponent.helpTooltip"; @@ -327,7 +329,7 @@ public class HelpTooltip { boolean hasTitle = StringUtil.isNotEmpty(title); if (hasTitle) { - tipPanel.add(new Header(), VerticalLayout.TOP); + tipPanel.add(hasHTMLTags(title) ? new Paragraph(title, false) : new Header(), VerticalLayout.TOP); } if (StringUtil.isNotEmpty(description)) { @@ -355,6 +357,10 @@ public class HelpTooltip { return tipPanel; } + private static boolean hasHTMLTags(@Nullable String string) { + return StringUtil.isNotEmpty(string) && HTML_TAG.matcher(string).find(); + } + private void installMouseListeners(@NotNull JComponent owner) { owner.addMouseListener(myMouseListener); owner.addMouseMotionListener(myMouseListener); @@ -500,7 +506,8 @@ public class HelpTooltip { Map tfa = font.getAttributes(); titleString = new AttributedString(title, tfa); dotString = new AttributedString(DOTS, tfa); - shortcutString = StringUtil.isNotEmpty(shortcut) ? new AttributedString(shortcut, font.getAttributes()) : null; + boolean hasShortcut = StringUtil.isNotEmpty(shortcut); + shortcutString = hasShortcut ? new AttributedString(shortcut, font.getAttributes()) : null; AttributedCharacterIterator paragraph = titleString.getIterator(); paragraphStart = paragraph.getBeginIndex(); @@ -511,7 +518,7 @@ public class HelpTooltip { int titleWidth = UIUtilities.stringWidth(this, tfm, title); FontMetrics fm = getFontMetrics(font); - titleWidth += StringUtil.isNotEmpty(shortcut) ? HGAP.get() + UIUtilities.stringWidth(this, fm, shortcut) : 0; + titleWidth += hasShortcut ? HGAP.get() + UIUtilities.stringWidth(this, fm, shortcut) : 0; boolean limitWidth = StringUtil.isNotEmpty(description) || link != null; isMultiline = limitWidth && titleWidth > MAX_WIDTH.get();