mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-66333 Quick documentation lookup on mouse hover
Include only <body> context to the quick doc preview
This commit is contained in:
@@ -65,23 +65,31 @@ public class DocPreviewUtil {
|
||||
if (fullText == null) {
|
||||
return header;
|
||||
}
|
||||
|
||||
int bodyStart = fullText.indexOf("<body>");
|
||||
if (bodyStart < 0) {
|
||||
return header;
|
||||
}
|
||||
bodyStart += "<body>".length();
|
||||
|
||||
int bodyEnd = fullText.indexOf("</body>");
|
||||
if (bodyEnd < 0) {
|
||||
return header;
|
||||
}
|
||||
|
||||
String body = fullText.substring(bodyStart, bodyEnd);
|
||||
|
||||
// The algorithm is:
|
||||
// 1. Prepare header to use;
|
||||
// 2. Process full text body as follows:
|
||||
// 2.1. Count non-markup symbols until desired row symbols number is exceeded;
|
||||
// 2.2. Insert <br> after that to start a new row;
|
||||
// 2.3. Stop processing as soon as the desired rows number is reached or the text is finished;
|
||||
// 3. Add closing tags for all non-matched open tags;
|
||||
// 1. Process full text body as follows:
|
||||
// 1.1. Count non-markup symbols until desired row symbols number is exceeded;
|
||||
// 1.2. Insert <br> after that to start a new row;
|
||||
// 1.3. Stop processing as soon as the desired rows number is reached or the text is finished;
|
||||
// 2. Add closing tags for all non-matched open tags;
|
||||
|
||||
final Context context = new Context(desiredRowsNumber, desiredSymbolsInRowNumber);
|
||||
int startParseOffset = 0;
|
||||
|
||||
//region 1. Prepare header to use
|
||||
|
||||
// Fill in HTML header.
|
||||
startParseOffset = process(fullText, startParseOffset, fullText.length(), getHeadParser(context));
|
||||
startParseOffset += "<body>".length();
|
||||
|
||||
// Include information about the library/module location.
|
||||
int bracket = header.indexOf(']');
|
||||
@@ -91,15 +99,15 @@ public class DocPreviewUtil {
|
||||
}
|
||||
|
||||
// Include information that is available at the given header (it's not count to the given rows/columns arguments).
|
||||
startParseOffset = process(fullText, startParseOffset, fullText.length(), getHeaderParser(context, header));
|
||||
startParseOffset = process(body, startParseOffset, body.length(), getHeaderParser(context, header));
|
||||
|
||||
//endregion
|
||||
|
||||
//region Parse body
|
||||
startParseOffset = process(fullText, startParseOffset, fullText.length(), getBodyParser(context));
|
||||
startParseOffset = process(body, startParseOffset, body.length(), getBodyParser(context));
|
||||
//endregion
|
||||
|
||||
if (qName != null && startParseOffset < fullText.length()) {
|
||||
if (qName != null && startParseOffset < body.length()) {
|
||||
context.buffer.append(String.format("<a href='psi_element://%s'><more></a>", qName));
|
||||
}
|
||||
|
||||
@@ -186,17 +194,6 @@ public class DocPreviewUtil {
|
||||
return start;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Callback getHeadParser(@NotNull Context context) {
|
||||
return new AbstractCallback(context, false) {
|
||||
@Override
|
||||
public boolean onOpenTag(@NotNull String name, @NotNull String text) {
|
||||
super.onOpenTag(name, text);
|
||||
return !"body".equals(name);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Callback getHeaderParser(@NotNull Context context, @NotNull final String header) {
|
||||
return new AbstractCallback(context, false) {
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ implements <a href="psi_element://java.io.Serializable"><code>java.io.Serializab
|
||||
'''
|
||||
|
||||
def expected = '''\
|
||||
<html><head> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </head><body>[< 1.7 >] java.lang<PRE>public final class java.lang.String<br/>extends <a href="psi_element://java.lang.Object"><code>Object</code></a><br/>implements <a href="psi_element://java.io.Serializable"><code>java.io.Serializable</code></a>, <a href="psi_element://java.lang.Comparable"><code>java.lang.Comparable</code></a><<a href="psi_element://java.lang.String"><code>java.lang.String<br/></code></a>>, <a href="psi_element://java.lang.CharSequence"><code>java.lang.CharSequence</code></a></PRE><br/>The <code>String</code> class represents character strings. All string literals<br/>in Java programs, such as <code>"abc"</code>, are implemented as instances<br/><a href='psi_element://java.lang.String'><more></a></body></html>\
|
||||
[< 1.7 >] java.lang<PRE>public final class java.lang.String<br/>extends <a href="psi_element://java.lang.Object"><code>Object</code></a><br/>implements <a href="psi_element://java.io.Serializable"><code>java.io.Serializable</code></a>, <a href="psi_element://java.lang.Comparable"><code>java.lang.Comparable</code></a><<a href="psi_element://java.lang.String"><code>java.lang.String<br/></code></a>>, <a href="psi_element://java.lang.CharSequence"><code>java.lang.CharSequence</code></a></PRE><br/>The <code>String</code> class represents character strings. All string literals<br/>in Java programs, such as <code>"abc"</code>, are implemented as instances<br/><a href='psi_element://java.lang.String'><more></a>\
|
||||
'''
|
||||
|
||||
def actual = DocPreviewUtil.buildPreview(header, "java.lang.String", fullText, 2, 60)
|
||||
|
||||
Reference in New Issue
Block a user