diff --git a/platform/lang-impl/src/com/intellij/lang/documentation/ide/ui/DocumentationPopupUI.kt b/platform/lang-impl/src/com/intellij/lang/documentation/ide/ui/DocumentationPopupUI.kt index 2055271995d6..7e5f1cfdcb40 100644 --- a/platform/lang-impl/src/com/intellij/lang/documentation/ide/ui/DocumentationPopupUI.kt +++ b/platform/lang-impl/src/com/intellij/lang/documentation/ide/ui/DocumentationPopupUI.kt @@ -88,10 +88,16 @@ internal class DocumentationPopupUI( gearActions.addAll(secondaryActions) gearActions.addSeparator() gearActions.addAll(primaryActions) - val corner = toolbarComponent(DefaultActionGroup(editSourceAction, gearActions), editorPane).apply { border = JBUI.Borders.empty(0, 0, contentOuterPadding - 3, settingsButtonPadding - 5) } + + ui.trackDocumentationCustomStyleChange(this){ + if (it != null) { + corner.isVisible = !it.customEnabled + } + } + ui.trackDocumentationBackgroundChange(this) { corner.background = it } diff --git a/platform/lang-impl/src/com/intellij/lang/documentation/ide/ui/DocumentationUI.kt b/platform/lang-impl/src/com/intellij/lang/documentation/ide/ui/DocumentationUI.kt index 5b74177798af..7f53de99af61 100644 --- a/platform/lang-impl/src/com/intellij/lang/documentation/ide/ui/DocumentationUI.kt +++ b/platform/lang-impl/src/com/intellij/lang/documentation/ide/ui/DocumentationUI.kt @@ -42,16 +42,12 @@ import com.intellij.util.ui.UIUtil import com.intellij.util.ui.accessibility.ScreenReader import kotlinx.coroutines.* import kotlinx.coroutines.channels.BufferOverflow -import kotlinx.coroutines.flow.MutableSharedFlow -import kotlinx.coroutines.flow.SharedFlow -import kotlinx.coroutines.flow.asSharedFlow -import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.* import org.jetbrains.annotations.Nls import org.jsoup.Jsoup import org.jsoup.nodes.Document import java.awt.Color import java.awt.Font -import java.awt.Graphics import java.awt.Rectangle import javax.swing.JComponent import javax.swing.JLabel @@ -90,6 +86,8 @@ internal class DocumentationUI( private val switcher: DefinitionSwitcher private var contentKind: ContentKind? = null + private val customStyleFlow: MutableStateFlow = MutableStateFlow(null) + init { scrollPane = DocumentationScrollPane() editorPane = DocumentationHintEditorPane(project, DocumentationScrollPane.keyboardActions(scrollPane)) { @@ -206,6 +204,25 @@ internal class DocumentationUI( } } + /** + * Tracks changes to a custom style and invokes the provided callback when the style changes. + * + * @param disposable A disposable object to manage the lifecycle of style change tracking. The tracking will stop when this disposable is disposed. + * @param onChange A callback function that is invoked whenever the custom style changes. The function receives the updated `CustomStyle` or `null` if no style is available. + */ + fun trackDocumentationCustomStyleChange(disposable: Disposable, onChange: (CustomStyle?) -> Unit) { + val job = cs.launch { + customStyleFlow.collectLatest { + withContext(Dispatchers.EDT) { + onChange(it) + } + } + } + Disposer.register(disposable) { + job.cancel() + } + } + private fun clearImages() { imageResolver = null } @@ -285,6 +302,9 @@ internal class DocumentationUI( } } + + internal data class CustomStyle(val backgroundColor: Color, val customEnabled: Boolean) + private data class DecoratedData(@NlsSafe val html: String, val decoratedStyle: DecoratedStyle?) private data class DecoratedStyle(val fontSize: Float, val backgroundColor: Color) private data class PreviousDecoratedStyle(val fontSize: FontSize, val backgroundColor: Color) @@ -378,6 +398,7 @@ internal class DocumentationUI( editorPane.isCustomSettingsEnabled = true editorPane.setFont(UIUtil.getFontWithFallback(editorPane.getFontName(), Font.PLAIN, JBUIScale.scale(decoratedStyle.fontSize).toInt())) editorPane.background = decoratedStyle.backgroundColor + customStyleFlow.value = CustomStyle(decoratedStyle.backgroundColor, true) } else { val localInitialDecoratedData = initialDecoratedData @@ -385,6 +406,7 @@ internal class DocumentationUI( editorPane.isCustomSettingsEnabled = false editorPane.background = localInitialDecoratedData.backgroundColor editorPane.applyFontProps(localInitialDecoratedData.fontSize) + customStyleFlow.value = CustomStyle(localInitialDecoratedData.backgroundColor, false) } } }