IJPL-787 JBHtmlPane: add support for rendering <hr> - no need to override <hr> behavior in tooltips

GitOrigin-RevId: c1284dade5c328b235a926def092e28fd5ace43f
This commit is contained in:
Piotr Tomiak
2024-03-07 21:18:57 +00:00
committed by intellij-monorepo-bot
parent fcc88475d8
commit 587da28340
2 changed files with 7 additions and 27 deletions
@@ -289,11 +289,11 @@ class JavaDocumentationTest : LightJavaCodeInsightFixtureTestCase() {
val actual = JavaExternalDocumentationTest.getDocumentationText(myFixture.project, input)
val expected = "<html><div class='content'>Candidates for method call <b>s.<wbr>regionMatches()</b> are:<br>" +
val expected = "<html><head></head><body><div class=\"content\"><p>Candidates for method call <b>s.<wbr>regionMatches()</b> are:<br>" +
"<br>" +
"&nbsp;&nbsp;<a href=\"psi_element://java.lang.String#regionMatches(int, java.lang.String, int, int)\">boolean regionMatches(int, String, int, int)</a><br>" +
"&nbsp;&nbsp;<a href=\"psi_element://java.lang.String#regionMatches(boolean, int, java.lang.String, int, int)\">boolean regionMatches(boolean, int, String, int, int)</a><br>" +
"</div>"
"</p></div></body></html>"
TestCase.assertEquals(expected, actual)
}
@@ -309,11 +309,11 @@ class JavaDocumentationTest : LightJavaCodeInsightFixtureTestCase() {
val documentationManager = DocumentationManager.getInstance(myFixture.project)
JavaExternalDocumentationTest.getDocumentationText(myFixture.project, input) { component ->
val expected = "<html><div class='content'>Candidates for method call <b>s.<wbr>regionMatches()</b> are:<br>" +
val expected = "<html><head></head><body><div class=\"content\"><p>Candidates for method call <b>s.<wbr>regionMatches()</b> are:<br>" +
"<br>" +
"&nbsp;&nbsp;<a href=\"psi_element://java.lang.String#regionMatches(int, java.lang.String, int, int)\">boolean regionMatches(int, String, int, int)</a><br>" +
"&nbsp;&nbsp;<a href=\"psi_element://java.lang.String#regionMatches(boolean, int, java.lang.String, int, int)\">boolean regionMatches(boolean, int, String, int, int)</a><br>" +
"</div>"
"</p></div></body></html>"
assertEquals(expected, component.decoratedText)
documentationManager.navigateByLink(component, null, "psi_element://java.lang.String#regionMatches(int, java.lang.String, int, int)")
@@ -326,7 +326,7 @@ class JavaDocumentationTest : LightJavaCodeInsightFixtureTestCase() {
// Here we check that the covering module (SDK in this case) is rendered in decorated info
assertTrue(
component.decoratedText.contains("<div class=\"bottom\"><icon src=\"AllIcons.Nodes.PpLibFolder\"/>&nbsp;&lt; java 1.7 &gt;</div>"))
component.decoratedText.contains("<div class=\"bottom\"><icon src=\"AllIcons.Nodes.PpLibFolder\" />&nbsp;&lt; java 1.7 &gt;</div>"))
return@getDocumentationText null
}
}
@@ -29,7 +29,6 @@ import com.intellij.ui.components.JBHtmlPane;
import com.intellij.ui.components.JBHtmlPaneConfiguration;
import com.intellij.ui.components.JBHtmlPaneStyleConfiguration;
import com.intellij.ui.components.panels.Wrapper;
import com.intellij.ui.scale.JBUIScale;
import com.intellij.util.Alarm;
import com.intellij.util.messages.SimpleMessageBusConnection;
import com.intellij.util.ui.*;
@@ -39,14 +38,9 @@ import org.jetbrains.annotations.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.html.HTML;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.lang.reflect.Field;
import java.util.Collections;
// Android team doesn't want to use new mockito for now, so, class cannot be final
@@ -722,22 +716,8 @@ public class IdeTooltipManager implements Disposable {
JBHtmlPaneConfiguration paneConfiguration = new JBHtmlPaneConfiguration(
Collections.emptyMap(), url -> null, icon -> null,
color -> StyleSheetUtil.loadStyleSheet("pre {white-space: pre-wrap;} code, pre {overflow-wrap: anywhere;}"),
null, Collections.singletonList(
(elem, view) -> {
AttributeSet attrs = elem.getAttributes();
if (attrs.getAttribute(AbstractDocument.ElementNameAttribute) == null &&
attrs.getAttribute(StyleConstants.NameAttribute) == HTML.Tag.HR) {
try {
Field field = view.getClass().getDeclaredField("size");
field.setAccessible(true);
field.set(view, JBUIScale.scale(1));
}
catch (Exception ignored) {
}
}
return view;
}
));
null, Collections.emptyList()
);
Ref<Boolean> prefSizeWasComputed = new Ref<>(false);