IDEA-246399 Quick doc pane is opened when clicking external links in rendered Doc
authorDmitry Batrak <Dmitry.Batrak@jetbrains.com>
Thu, 13 Aug 2020 16:49:14 +0000 (19:49 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Thu, 13 Aug 2020 16:49:34 +0000 (16:49 +0000)
GitOrigin-RevId: ddc202bb3232d4c1801fa7331d9209c77a568ee1

platform/lang-impl/src/com/intellij/codeInsight/documentation/render/DocRenderer.java

index 5c4256542932a2e8e20374451046b39f3054d26c..de1c8d3f6d949c053e031b67ac967fe7c1b1df32 100644 (file)
@@ -6,6 +6,7 @@ import com.intellij.codeInsight.documentation.DocumentationComponent;
 import com.intellij.codeInsight.documentation.DocumentationManager;
 import com.intellij.codeInsight.documentation.QuickDocUtil;
 import com.intellij.icons.AllIcons;
+import com.intellij.ide.BrowserUtil;
 import com.intellij.ide.IdeEventQueue;
 import com.intellij.ide.ui.UISettings;
 import com.intellij.openapi.Disposable;
@@ -316,6 +317,10 @@ class DocRenderer implements EditorCustomElementRenderer {
                                  @NotNull PsiElement context,
                                  @NotNull String linkUrl,
                                  @NotNull Rectangle linkLocationWithinInlay) {
+    if (isExternalLink(linkUrl)) {
+      BrowserUtil.open(linkUrl);
+      return;
+    }
     Project project = context.getProject();
     DocumentationManager documentationManager = DocumentationManager.getInstance(project);
     if (QuickDocUtil.getActiveDocComponent(project) == null) {
@@ -351,6 +356,11 @@ class DocRenderer implements EditorCustomElementRenderer {
     }
   }
 
+  private static boolean isExternalLink(@NotNull String linkUrl) {
+    String l = linkUrl.toLowerCase(Locale.ROOT);
+    return l.startsWith("http://") || l.startsWith("https://");
+  }
+
   private static EditorKit createEditorKit(@NotNull Editor editor) {
     HTMLEditorKit editorKit = new MyEditorKit();
     editorKit.getStyleSheet().addStyleSheet(getStyleSheet(editor));