Skip to content

Commit

Permalink
chore: clean up color schema, remove unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
acke committed Sep 25, 2024
1 parent 1294a5f commit f76ccc3
Showing 1 changed file with 17 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package io.snyk.plugin.ui.jcef

import com.intellij.openapi.editor.colors.ColorKey
import com.intellij.openapi.editor.colors.EditorColors
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.ui.jcef.JBCefBrowserBase
import com.intellij.util.ui.JBUI
import com.intellij.ui.JBColor
import com.intellij.util.ui.UIUtil
import org.cef.browser.CefBrowser
import org.cef.browser.CefFrame
Expand All @@ -17,34 +15,6 @@ class ThemeBasedStylingGenerator {
return "#%02x%02x%02x".format(color.red, color.green, color.blue)
}

fun shift(
colorComponent: Int,
d: Double,
): Int {
val n = (colorComponent * d).toInt()
return n.coerceIn(0, 255)
}

fun getCodeDiffColors(
baseColor: Color,
isHighContrast: Boolean,
): Pair<Color, Color> {
val addedColor =
if (isHighContrast) {
Color(28, 68, 40) // high contrast green
} else {
Color(shift(baseColor.red, 0.75), baseColor.green, shift(baseColor.blue, 0.75))
}

val removedColor =
if (isHighContrast) {
Color(84, 36, 38) // high contrast red
} else {
Color(shift(baseColor.red, 1.25), shift(baseColor.green, 0.85), shift(baseColor.blue, 0.85))
}
return Pair(addedColor, removedColor)
}

@Suppress("UNUSED_PARAMETER")
fun generate(jbCefBrowser: JBCefBrowserBase): CefLoadHandlerAdapter {
val isDarkTheme = EditorColorsManager.getInstance().isDarkEditor
Expand All @@ -58,21 +28,22 @@ class ThemeBasedStylingGenerator {
httpStatusCode: Int,
) {
if (frame.isMain) {
val baseColor = UIUtil.getTextFieldBackground() //TODO Replace with JBUI.CurrentTheme colors
val (addedColor, removedColor) = getCodeDiffColors(baseColor, isHighContrast) //TODO Replace with JBUI.CurrentTheme colors
val dataFlowColor = toCssHex(baseColor)
val editorColor = toCssHex(baseColor)

val textColor = toCssHex(JBUI.CurrentTheme.Tree.FOREGROUND)
val linkColor = toCssHex(JBUI.CurrentTheme.Link.Foreground.ENABLED)
val buttonColor = toCssHex(JBUI.CurrentTheme.Button.defaultButtonColorStart())

val borderColor = toCssHex(JBUI.CurrentTheme.CustomFrameDecorations.separatorForeground())
val labelColor = toCssHex(JBUI.CurrentTheme.Label.foreground())
val background = toCssHex(JBUI.CurrentTheme.Tree.BACKGROUND)
val issuePanelBackground = toCssHex(JBUI.CurrentTheme.DefaultTabs.background())
val tabUnderline = toCssHex(JBUI.CurrentTheme.DefaultTabs.underlineColor())
val redCodeBlock = toCssHex(JBUI.CurrentTheme.Banner.ERROR_BORDER_COLOR)
val greenCodeBlock = toCssHex(JBUI.CurrentTheme.Banner.SUCCESS_BORDER_COLOR)
val aiCodeBg = UIUtil.getTextFieldBackground()
val codeBlockText = toCssHex(JBUI.CurrentTheme.Tree.FOREGROUND)
val buttonColor = toCssHex(JBUI.CurrentTheme.Button.defaultButtonColorStart())

val globalScheme = EditorColorsManager.getInstance().globalScheme
val tearLineColor = globalScheme.getColor(ColorKey.find("TEARLINE_COLOR")) //TODO Replace with JBUI.CurrentTheme colors
val tabItemHoverColor = globalScheme.getColor(ColorKey.find("INDENT_GUIDE")) //TODO Replace with JBUI.CurrentTheme colors
val codeTagBgColor = globalScheme.getColor(EditorColors.GUTTER_BACKGROUND) ?: globalScheme.defaultBackground //TODO Replace with JBUI.CurrentTheme colors

val themeScript = """
(function(){
Expand All @@ -82,23 +53,22 @@ class ThemeBasedStylingGenerator {
window.themeApplied = true;
const style = getComputedStyle(document.documentElement);
const properties = {
'--text-color': "$textColor",
'--text-color': "$codeBlockText",
'--link-color': "$linkColor",
'--data-flow-body-color': "$dataFlowColor",
'--example-line-added-color': "${toCssHex(addedColor)}",
'--example-line-removed-color': "${toCssHex(removedColor)}",
'--data-flow-body-color': "$background",
'--example-line-added-color': "$greenCodeBlock",
'--example-line-removed-color': "$redCodeBlock",
'--tab-item-github-icon-color': "$textColor",
'--tab-item-hover-color': "${tabItemHoverColor?.let { toCssHex(it) }}",
'--tab-item-hover-color': "$tabUnderline",
'--scrollbar-thumb-color': "${tearLineColor?.let { toCssHex(it) }}",
'--tabs-bottom-color': "${tearLineColor?.let { toCssHex(it) }}",
'--tabs-bottom-color': "$issuePanelBackground",
'--border-color': "$borderColor",
'--editor-color': "$editorColor",
'--editor-color': "${toCssHex(aiCodeBg)}",
'--label-color': "'$labelColor'",
'--container-background-color': "${toCssHex(codeTagBgColor)}",
'--container-background-color': "${toCssHex(aiCodeBg)}",
'--generated-ai-fix-button-background-color': "$buttonColor",
'--dark-button-border-default': "$borderColor",
'--dark-button-default': "$buttonColor",
};
for (let [property, value] of Object.entries(properties)) {
document.documentElement.style.setProperty(property, value);
Expand Down

0 comments on commit f76ccc3

Please sign in to comment.