From cbb13e187c3254d19a474623b1403752bb3b9fcf Mon Sep 17 00:00:00 2001 From: Piotr Kukielka Date: Fri, 15 Nov 2024 17:59:40 +0100 Subject: [PATCH 1/2] Propagate font settings from JetBrains to webview --- .../cody/sidebar/WebThemeController.kt | 21 ++++++++++++++++--- .../sourcegraph/cody/ui/web/WebUIService.kt | 9 +++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/sourcegraph/cody/sidebar/WebThemeController.kt b/src/main/kotlin/com/sourcegraph/cody/sidebar/WebThemeController.kt index 34b9754474..80fa1b5bad 100644 --- a/src/main/kotlin/com/sourcegraph/cody/sidebar/WebThemeController.kt +++ b/src/main/kotlin/com/sourcegraph/cody/sidebar/WebThemeController.kt @@ -1,11 +1,15 @@ package com.sourcegraph.cody.sidebar +import com.intellij.ide.ui.UISettings +import com.intellij.ide.ui.UISettingsListener +import com.intellij.openapi.Disposable +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.invokeLater import com.sourcegraph.config.ThemeUtil import java.awt.Color import javax.swing.UIManager -class WebThemeController { +class WebThemeController(parentDisposable: Disposable) { private var themeChangeListener: ((WebTheme) -> Unit)? = null init { @@ -14,6 +18,13 @@ class WebThemeController { invokeLater { themeChangeListener?.invoke(getTheme()) } } } + + ApplicationManager.getApplication() + .messageBus + .connect(parentDisposable) + .subscribe( + UISettingsListener.TOPIC, + UISettingsListener { _ -> invokeLater { themeChangeListener?.invoke(getTheme()) } }) } fun setThemeChangeListener(listener: (WebTheme) -> Unit) { @@ -21,12 +32,16 @@ class WebThemeController { } fun getTheme(): WebTheme { - val themeVariables = + val colorVariables = UIManager.getDefaults() .filterValues { it is Color } .mapKeys { toCSSVariableName(it.key.toString()) } .mapValues { toCSSColor(it.value as Color) } - return WebTheme(ThemeUtil.isDarkTheme(), themeVariables) + + val fontSizeVariable = + (toCSSVariableName("font-size") to "${UISettings.getInstance().fontSize}px") + + return WebTheme(ThemeUtil.isDarkTheme(), colorVariables + fontSizeVariable) } private fun toCSSColor(value: Color) = diff --git a/src/main/kotlin/com/sourcegraph/cody/ui/web/WebUIService.kt b/src/main/kotlin/com/sourcegraph/cody/ui/web/WebUIService.kt index 197743cf4d..809112b5d7 100644 --- a/src/main/kotlin/com/sourcegraph/cody/ui/web/WebUIService.kt +++ b/src/main/kotlin/com/sourcegraph/cody/ui/web/WebUIService.kt @@ -1,6 +1,7 @@ package com.sourcegraph.cody.ui.web import com.google.gson.JsonParser +import com.intellij.openapi.Disposable import com.intellij.openapi.application.runInEdt import com.intellij.openapi.components.Service import com.intellij.openapi.components.service @@ -31,7 +32,7 @@ internal data class WebUIProxyCreationGate( // - Pushes theme updates into Webviews. // - Routes postMessage from host to Webviews. @Service(Service.Level.PROJECT) -class WebUIService(private val project: Project) { +class WebUIService(private val project: Project) : Disposable { companion object { @JvmStatic fun getInstance(project: Project): WebUIService = project.service() } @@ -78,8 +79,8 @@ class WebUIService(private val project: Project) { } } - private var themeController = - WebThemeController().apply { setThemeChangeListener { updateTheme(it) } } + private val themeController = + WebThemeController(this).apply { setThemeChangeListener { updateTheme(it) } } private fun updateTheme(theme: WebTheme) { synchronized(proxies) { @@ -164,4 +165,6 @@ class WebUIService(private val project: Project) { internal fun setTitle(handle: String, title: String) { withProxy(handle) { it.title = title } } + + override fun dispose() {} } From 98a7c7bc6e710315a17be6e85f81195485ce92be Mon Sep 17 00:00:00 2001 From: Piotr Kukielka Date: Mon, 18 Nov 2024 10:38:03 +0100 Subject: [PATCH 2/2] Bump Cody commit --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 917e8f95d9..eb03c41d3e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,4 +25,4 @@ org.gradle.jvmargs=-Xmx4g -Xms500m nodeBinaries.commit=8755ae4c05fd476cd23f2972049111ba436c86d4 nodeBinaries.version=v20.12.2 cody.autocomplete.enableFormatting=true -cody.commit=6ac4a8c1831ad3945fc16f20b8f21947897d3d14 +cody.commit=05cdd34e7dc7e7e7652e71140729dcbf2cb33a14