diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/theme/ThemeBrowserAdapter.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/theme/ThemeBrowserAdapter.kt index 7408e2f9780..e891fa34e65 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/theme/ThemeBrowserAdapter.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/theme/ThemeBrowserAdapter.kt @@ -26,6 +26,7 @@ class ThemeBrowserAdapter { } private fun buildJsCodeToUpdateTheme(theme: AmazonQTheme) = buildString { + val (bg, altBg, inputBg) = determineInputAndBgColor(theme) appendDarkMode(theme.darkMode) append("{\n") @@ -42,14 +43,14 @@ class ThemeBrowserAdapter { append(CssVariable.TextColorWeak, theme.inactiveText) append(CssVariable.TextColorDisabled, theme.inactiveText) - append(CssVariable.Background, theme.editorBackground) - append(CssVariable.BackgroundAlt, theme.background) - append(CssVariable.CardBackground, theme.editorBackground) - append(CssVariable.CardBackgroundAlt, theme.background) + append(CssVariable.Background, bg) + append(CssVariable.BackgroundAlt, altBg) + append(CssVariable.CardBackground, bg) + append(CssVariable.CardBackgroundAlt, altBg) append(CssVariable.BorderDefault, theme.border) append(CssVariable.TabActive, theme.activeTab) - append(CssVariable.InputBackground, theme.textFieldBackground) + append(CssVariable.InputBackground, inputBg) append(CssVariable.ButtonBackground, theme.buttonBackground) append(CssVariable.ButtonForeground, theme.buttonForeground) @@ -110,4 +111,15 @@ class ThemeBrowserAdapter { // Some font names have characters that require them to be wrapped in quotes in the CSS variable, for example if they have spaces or a period. private fun Font.toCssFontFamily(fallback: String = "system-ui") = "\"$family\", $fallback" + + // darkest = bg, second darkest is alt bg, lightest is input bg + private fun determineInputAndBgColor(theme: AmazonQTheme): Triple { + val colors = arrayOf(theme.editorBackground, theme.background, theme.textFieldBackground).sortedWith( + Comparator.comparing { + // luma calculation for brightness + (0.2126 * it.red) + (0.7152 * it.green) + (0.0722 * it.blue) + } + ) + return Triple(colors[0], colors[1], colors[2]) + } }