IJPL-148864 Add a toggle for underlined hyperlink in JBHtmlEditorKit

Previous behavior is maintained by setting default to true.

closes https://github.com/JetBrains/intellij-community/pull/2770

GitOrigin-RevId: a4002d2f2161c35cfea50606b517f1304d336507
This commit is contained in:
Brice Dutheil
2024-06-25 09:04:46 +00:00
committed by intellij-monorepo-bot
parent 2a1d8d17a6
commit f6e2dcc621
6 changed files with 39 additions and 2 deletions
@@ -8039,6 +8039,7 @@ c:com.intellij.ui.components.JBComboBoxLabel
- f:getIconResolver():kotlin.jvm.functions.Function1
- f:getImageResolverFactory():kotlin.jvm.functions.Function1
- f:getKeyboardActions():java.util.Map
- f:getUnderlinedHoveredHyperlink():Z
- f:iconResolver(kotlin.jvm.functions.Function1):com.intellij.ui.components.JBHtmlPaneConfiguration$Builder
- f:imageResolverFactory(kotlin.jvm.functions.Function1):com.intellij.ui.components.JBHtmlPaneConfiguration$Builder
- f:keyboardActions(java.util.Map):com.intellij.ui.components.JBHtmlPaneConfiguration$Builder
@@ -8046,6 +8047,7 @@ c:com.intellij.ui.components.JBComboBoxLabel
- f:setFontResolver(com.intellij.util.ui.CSSFontResolver):V
- f:setIconResolver(kotlin.jvm.functions.Function1):V
- f:setImageResolverFactory(kotlin.jvm.functions.Function1):V
- f:setUnderlinedHoveredHyperlink(Z):V
*f:com.intellij.ui.components.JBHtmlPaneConfiguration$Companion
- f:builder():com.intellij.ui.components.JBHtmlPaneConfiguration$Builder
*f:com.intellij.ui.components.JBHtmlPaneStyleConfiguration
@@ -145,6 +145,7 @@ open class JBHtmlPane(
val editorKit = HTMLEditorKitBuilder()
.replaceViewFactoryExtensions(*extensions.toTypedArray())
.withFontResolver(myPaneConfiguration.fontResolver ?: service.defaultEditorCssFontResolver())
.withUnderlinedHoveredHyperlink(myPaneConfiguration.underlinedHoveredHyperlink)
.build()
updateDocumentationPaneDefaultCssRules(editorKit)
@@ -48,6 +48,7 @@ class JBHtmlPaneConfiguration private constructor(builder: Builder) {
internal val iconResolver: (String) -> Icon? = builder.iconResolver
internal val customStyleSheetProviders: List<(backgroundColor: Color) -> StyleSheet> = builder.customStyleSheetProviders.toList()
internal val fontResolver: CSSFontResolver? = builder.fontResolver
internal val underlinedHoveredHyperlink = builder.underlinedHoveredHyperlink
internal val extensions: List<ExtendableHTMLViewFactory.Extension> = builder.extensions.toList()
constructor() : this(builder())
@@ -97,6 +98,17 @@ class JBHtmlPaneConfiguration private constructor(builder: Builder) {
*/
var fontResolver: CSSFontResolver? = null
/**
* Toggle whether hyperlinks are underlined when hovered.
*
* This is useful if another implementation needs to apply a different style
* to hyperlinks when hovered (this can be done by adding an [javax.swing.event.HyperlinkListener]
* to the [JBHtmlPane]).
*
* Default is true.
*/
var underlinedHoveredHyperlink: Boolean = true
/**
* Provide a list of additional extensions for the [ExtendableHTMLViewFactory]
*/
+2
View File
@@ -3783,6 +3783,7 @@ f:com.intellij.util.ui.HTMLEditorKitBuilder
- f:withFontResolver(com.intellij.util.ui.CSSFontResolver):com.intellij.util.ui.HTMLEditorKitBuilder
- f:withGapsBetweenParagraphs():com.intellij.util.ui.HTMLEditorKitBuilder
- f:withStyleSheet(javax.swing.text.html.StyleSheet):com.intellij.util.ui.HTMLEditorKitBuilder
- f:withUnderlinedHoveredHyperlink(Z):com.intellij.util.ui.HTMLEditorKitBuilder
- f:withViewFactoryExtensions(kotlin.jvm.functions.Function2[]):com.intellij.util.ui.HTMLEditorKitBuilder
- f:withWordWrapViewFactory():com.intellij.util.ui.HTMLEditorKitBuilder
- f:withoutContentCss():com.intellij.util.ui.HTMLEditorKitBuilder
@@ -3935,6 +3936,7 @@ c:com.intellij.util.ui.JBHtmlEditorKit
- install(javax.swing.JEditorPane):V
- setFontResolver(com.intellij.util.ui.CSSFontResolver):V
- setStyleSheet(javax.swing.text.html.StyleSheet):V
- setUnderlineHoveredHyperlink(Z):V
c:com.intellij.util.ui.JBHtmlEditorKit$JBHtmlFactory
- javax.swing.text.html.HTMLEditorKit$HTMLFactory
- <init>():V
@@ -19,6 +19,7 @@ class HTMLEditorKitBuilder {
private var needGapsBetweenParagraphs = false
private var loadCssFromFile = true
private var fontResolver: CSSFontResolver? = null
private var underlinedHoveredHyperlink = true
/**
* Allows replacing default [ExtendableHTMLViewFactory] extensions
@@ -80,10 +81,15 @@ class HTMLEditorKitBuilder {
fontResolver = resolver
}
fun withUnderlinedHoveredHyperlink(flag: Boolean): HTMLEditorKitBuilder = apply {
underlinedHoveredHyperlink = flag
}
fun build(): HTMLEditorKit {
val styleSheet = overriddenRootStyle ?: createHtmlStyleSheet()
return JBHtmlEditorKit(viewFactory, styleSheet, !loadCssFromFile).apply {
if (fontResolver != null) setFontResolver(fontResolver)
if (fontResolver != null) { setFontResolver(fontResolver) }
setUnderlineHoveredHyperlink(underlinedHoveredHyperlink)
}
}
@@ -38,6 +38,7 @@ public class JBHtmlEditorKit extends HTMLEditorKit {
private final @NotNull HTMLEditorKit.LinkController myLinkController = new MouseExitSupportLinkController();
private final @NotNull HyperlinkListener myHyperlinkListener = new LinkUnderlineListener();
private final boolean myDisableLinkedCss;
private boolean myUnderlineHoveredHyperlink = true;
private @Nullable CSSFontResolver myFontResolver;
@@ -74,6 +75,17 @@ public class JBHtmlEditorKit extends HTMLEditorKit {
myStyle = defaultStyle;
}
/**
* Toggle whether hyperlinks are underlined when hovered.
*
* This is useful if another implementation needs to apply a different style
* to hyperlinks when hovered (this can be done by adding a {@link HyperlinkListener}
* to the {@link JEditorPane}).
*/
public void setUnderlineHoveredHyperlink(boolean underlineHoveredHyperlink) {
myUnderlineHoveredHyperlink = underlineHoveredHyperlink;
}
/**
* This allows to impact resolution of fonts from CSS attributes of text
*/
@@ -135,7 +147,9 @@ public class JBHtmlEditorKit extends HTMLEditorKit {
pane.removePropertyChangeListener(this);
}
});
pane.addHyperlinkListener(myHyperlinkListener);
if (myUnderlineHoveredHyperlink) {
pane.addHyperlinkListener(myHyperlinkListener);
}
java.util.List<LinkController> listeners1 = filterLinkControllerListeners(pane.getMouseListeners());
java.util.List<LinkController> listeners2 = filterLinkControllerListeners(pane.getMouseMotionListeners());