updating jetbrains colors

This commit is contained in:
Dallin Romney 2025-02-13 03:09:27 -08:00
parent 807aefa91c
commit 701c0dd950
7 changed files with 101 additions and 80 deletions

View file

@ -40,4 +40,5 @@ export type ToWebviewFromIdeOrCoreProtocol = {
signInToControlPlane: [undefined, void];
openDialogMessage: ["account", void];
"docs/suggestions": [PackageDocsResult[], void];
"jetbrains/setColors": [Record<string, string>, void];
};

View file

@ -37,6 +37,7 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent
import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent
import com.intellij.ide.ui.LafManagerListener
fun showTutorial(project: Project) {
val tutorialFileName = getTutorialFileName()
@ -182,7 +183,7 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {
val changedURIs = events.filterIsInstance<VFileContentChangeEvent>()
.mapNotNull { event -> event.file.toUriOrNull() }
// Send "files/changed" message if there are any content changes
// Notify core of content changes
if (changedURIs.isNotEmpty()) {
val data = mapOf("files" to changedURIs)
continuePluginService.coreMessenger?.request("files/changed", data, null) { _ -> }
@ -190,6 +191,16 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {
}
})
// Listen for theme changes
connection.subscribe(LafManagerListener.TOPIC, LafManagerListener {
// val isDarkTheme = UIManager.getLookAndFeel()?.name?.lowercase()?.contains("dark") ?: false
val colors = GetTheme().getTheme();
continuePluginService.sendToWebview(
"jetbrains/setColors",
colors
)
})
// Listen for clicking settings button to start the auth flow
val authService = service<ContinueAuthService>()
val initialSessionInfo = authService.loadControlPlaneSessionInfo()

View file

@ -1,15 +1,12 @@
package com.github.continuedev.continueintellijextension.`continue`
import com.intellij.codeInsight.template.impl.TemplateColors
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
import com.intellij.openapi.editor.colors.EditorColors
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.editor.colors.EditorColorsScheme
import com.intellij.openapi.editor.colors.TextAttributesKey
import java.awt.Color
import kotlin.math.max
import kotlin.math.min
import com.intellij.ui.JBColor
import com.intellij.ui.ColorUtil
class GetTheme {
fun getSecondaryDark(): Color {
@ -42,62 +39,64 @@ class GetTheme {
}
fun getTheme(): Map<String, String> {
fun toHex(color: Color): String {
return String.format("#%02x%02x%02x", color.red, color.green, color.blue)
}
try {
val globalScheme = EditorColorsManager.getInstance().globalScheme
val defaultBackground = globalScheme.defaultBackground
val defaultForeground = globalScheme.defaultForeground
val highlight = globalScheme.getColor(EditorColors.MODIFIED_TAB_ICON_COLOR) ?: defaultForeground
val defaultBackgroundHex =
String.format("#%02x%02x%02x", defaultBackground.red, defaultBackground.green, defaultBackground.blue)
val defaultForegroundHex =
String.format("#%02x%02x%02x", defaultForeground.red, defaultForeground.green, defaultForeground.blue)
val highlightHex = String.format("#%02x%02x%02x", highlight.red, highlight.green, highlight.blue)
val background = JBColor.background()
val foreground = JBColor.foreground()
val grayscale =
(defaultBackground.red * 0.3 + defaultBackground.green * 0.59 + defaultBackground.blue * 0.11).toInt()
val buttonBackground = JBColor.namedColor("Button.background")
val buttonForeground = JBColor.namedColor("Button.foreground")
val adjustedRed: Int
val adjustedGreen: Int
val adjustedBlue: Int
val badgeBackground = JBColor.namedColor("Panel.background")
val badgeForeground = JBColor.namedColor("Panel.foreground")
val tint: Int = 20
if (grayscale > 128) { // if closer to white
adjustedRed = max(0, defaultBackground.red - tint)
adjustedGreen = max(0, defaultBackground.green - tint)
adjustedBlue = max(0, defaultBackground.blue - tint)
} else { // if closer to black
adjustedRed = min(255, defaultBackground.red + tint)
adjustedGreen = min(255, defaultBackground.green + tint)
adjustedBlue = min(255, defaultBackground.blue + tint)
}
val inputBackground = JBColor.namedColor("TextField.background")
val secondaryDarkHex = String.format("#%02x%02x%02x", adjustedRed, adjustedGreen, adjustedBlue)
val border = JBColor.border()
val focusBorder = JBColor.namedColor("Focus.borderColor")
return mapOf(
"--vscode-editor-foreground" to defaultForegroundHex,
"--vscode-editor-background" to defaultBackgroundHex,
val editorScheme = EditorColorsManager.getInstance().globalScheme
"--vscode-button-background" to defaultBackgroundHex,
"--vscode-button-foreground" to defaultForegroundHex,
val editorBackground = editorScheme.defaultBackground
val editorForeground = editorScheme.defaultForeground
"--vscode-list-activeSelectionBackground" to defaultBackgroundHex,
val actionHoverBackground = JBColor.namedColor("ActionButton.hoverBackground")
// val inputBorder = JBColor.namedColor("TextField.borderColor")
// val focus = JBColor.namedColor("focusColor")
val highlight = editorScheme.getColor(EditorColors.MODIFIED_TAB_ICON_COLOR) ?: editorForeground
"--vscode-quickInputList-focusForeground" to defaultForegroundHex,
"--vscode-quickInput-background" to secondaryDarkHex,
val findMatchBackground = editorScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES)?.backgroundColor ?: Color(255, 221, 0)
"--vscode-badge-background" to highlightHex,
"--vscode-badge-foreground" to defaultForegroundHex,
val theme = mapOf(
"--vscode-editor-foreground" to toHex(editorForeground),
"--vscode-editor-background" to toHex(editorBackground),
"--vscode-input-background" to secondaryDarkHex,
"--vscode-input-border" to "#80808080",
"--vscode-sideBar-background" to defaultBackgroundHex,
"--vscode-sideBar-border" to "#80808080",
"--vscode-focusBorder" to highlightHex,
"--vscode-button-background" to toHex(buttonBackground),
"--vscode-button-foreground" to toHex(buttonForeground),
"--vscode-commandCenter-activeBorder" to highlightHex,
"--vscode-commandCenter-inactiveBorder" to "#80808080"
"--vscode-list-activeSelectionBackground" to toHex(actionHoverBackground),
"--vscode-quickInputList-focusForeground" to toHex(foreground),
"--vscode-quickInput-background" to toHex(inputBackground),
"--vscode-badge-background" to toHex(badgeBackground),
"--vscode-badge-foreground" to toHex(badgeForeground),
"--vscode-input-background" to toHex(inputBackground),
"--vscode-input-border" to toHex(border),
"--vscode-sideBar-background" to toHex(background),
"--vscode-sideBar-border" to toHex(border),
"--vscode-focusBorder" to toHex(focusBorder),
"--vscode-commandCenter-activeBorder" to toHex(focusBorder),
"--vscode-commandCenter-inactiveBorder" to toHex(border),
"--vscode-editor-findMatchHighlightBackground" to toHex(findMatchBackground) + "40"
)
return theme
} catch (error: Error) {
return mapOf()
}

View file

@ -202,14 +202,14 @@ function AddDocsDialog() {
<div>
<PencilIcon
data-tooltip-id={id + "-edit"}
className="lightgray h-3 w-3"
className="text-lightgray h-3 w-3"
/>
<ToolTip id={id + "-edit"} place="bottom">
This may not be a docs page
</ToolTip>
</div>
) : (
<PlusIcon className="text-foreground-muted h-3.5 w-3.5" />
<PlusIcon className="text-lightgray h-3.5 w-3.5" />
)}
</div>
<div className="flex items-center gap-0.5">

View file

@ -9,18 +9,19 @@ export const VSC_BUTTON_FOREGROUND_VAR = "--vscode-button-foreground";
export const VSC_EDITOR_BACKGROUND_VAR = "--vscode-editor-background";
export const VSC_LIST_SELECTION_BACKGROUND_VAR =
"--vscode-list-activeSelectionBackground";
export const VSC_FOCUS_BORDER = "--vscode-focus-border";
export const VSC_FOCUS_BORDER_VAR = "--vscode-focusBorder";
export const VSC_LIST_ACTIVE_FOREGROUND_VAR =
"--vscode-quickInputList-focusForeground";
export const VSC_QUICK_INPUT_BACKGROUND_VAR = "--vscode-quickInput-background";
export const VSC_INPUT_BORDER_VAR = "--vscode-input-border";
export const VSC_INPUT_BORDER_FOCUS_VAR = "--vscode-focusBorder";
export const VSC_BADGE_BACKGROUND_VAR = "--vscode-badge-background";
export const VSC_BADGE_FOREGROUND_VAR = "--vscode-badge-foreground";
export const VSC_COMMAND_CENTER_ACTIVE_BORDER_VAR =
"--vscode-commandCenter-activeBorder";
export const VSC_COMMAND_CENTER_INACTIVE_BORDER_VAR =
"--vscode-commandCenter-inactiveBorder";
export const VSC_FIND_MATCH_SELECTED_VAR =
"--vscode-editor-findMatchHighlightBackground";
export const VSC_THEME_COLOR_VARS = [
VSC_INPUT_BACKGROUND_VAR,
@ -30,15 +31,15 @@ export const VSC_THEME_COLOR_VARS = [
VSC_BUTTON_FOREGROUND_VAR,
VSC_EDITOR_BACKGROUND_VAR,
VSC_LIST_SELECTION_BACKGROUND_VAR,
VSC_FOCUS_BORDER,
VSC_FOCUS_BORDER_VAR,
VSC_LIST_ACTIVE_FOREGROUND_VAR,
VSC_QUICK_INPUT_BACKGROUND_VAR,
VSC_INPUT_BORDER_VAR,
VSC_INPUT_BORDER_FOCUS_VAR,
VSC_BADGE_BACKGROUND_VAR,
VSC_BADGE_FOREGROUND_VAR,
VSC_COMMAND_CENTER_ACTIVE_BORDER_VAR,
VSC_COMMAND_CENTER_INACTIVE_BORDER_VAR,
VSC_FIND_MATCH_SELECTED_VAR,
];
export const defaultBorderRadius = "5px";
@ -53,33 +54,14 @@ export const vscButtonBackground = `var(${VSC_BUTTON_BACKGROUND_VAR}, #1bbe84)`;
export const vscButtonForeground = `var(${VSC_BUTTON_FOREGROUND_VAR}, #ffffff)`;
export const vscEditorBackground = `var(${VSC_EDITOR_BACKGROUND_VAR}, ${VSC_BACKGROUND_VAR}, rgb(30 30 30))`;
export const vscListActiveBackground = `var(${VSC_LIST_SELECTION_BACKGROUND_VAR}, #1bbe84)`;
export const vscFocusBorder = `var(${VSC_FOCUS_BORDER}, #1bbe84)`;
export const vscFocusBorder = `var(${VSC_FOCUS_BORDER_VAR}, #1bbe84)`;
export const vscListActiveForeground = `var(${VSC_LIST_ACTIVE_FOREGROUND_VAR}, ${VSC_FOREGROUND_VAR})`;
export const vscInputBorder = `var(${VSC_INPUT_BORDER_VAR}, ${lightGray})`;
export const vscInputBorderFocus = `var(${VSC_INPUT_BORDER_FOCUS_VAR}, ${lightGray})`;
export const vscInputBorderFocus = `var(${VSC_FOCUS_BORDER_VAR}, ${lightGray})`;
export const vscBadgeBackground = `var(${VSC_BADGE_BACKGROUND_VAR}, #1bbe84)`;
export const vscCommandCenterActiveBorder = `var(${VSC_COMMAND_CENTER_ACTIVE_BORDER_VAR}, #1bbe84)`;
export const vscCommandCenterInactiveBorder = `var(${VSC_COMMAND_CENTER_INACTIVE_BORDER_VAR}, #1bbe84)`;
if (typeof document !== "undefined") {
const jetbrains = isJetBrains();
for (const colorVar of VSC_THEME_COLOR_VARS) {
if (jetbrains) {
const cached = localStorage.getItem(colorVar);
if (cached) {
document.body.style.setProperty(colorVar, cached);
}
}
// Remove alpha channel from colors
const value = getComputedStyle(document.documentElement).getPropertyValue(
colorVar,
);
if (colorVar.startsWith("#") && value.length > 7) {
document.body.style.setProperty(colorVar, value.slice(0, 7));
}
}
}
export const vscFindMatchSelected = `var(${VSC_FIND_MATCH_SELECTED_VAR}, rgba(255, 223, 0))`;
export function parseHexColor(hexColor: string): {
r: number;

View file

@ -124,7 +124,25 @@ function useSetup() {
// Override persisted state
dispatch(setInactive());
if (isJetBrains()) {
const jetbrains = isJetBrains();
for (const colorVar of VSC_THEME_COLOR_VARS) {
if (jetbrains) {
const cached = localStorage.getItem(colorVar);
if (cached) {
document.body.style.setProperty(colorVar, cached);
}
}
// Remove alpha channel from colors
const value = getComputedStyle(document.documentElement).getPropertyValue(
colorVar,
);
if (colorVar.startsWith("#") && value.length > 7) {
document.body.style.setProperty(colorVar, value.slice(0, 7));
}
}
if (jetbrains) {
// Save theme colors to local storage for immediate loading in JetBrains
ideMessenger.request("jetbrains/getColors", undefined).then((result) => {
if (result.status === "success") {
@ -160,6 +178,17 @@ function useSetup() {
}
}, []);
useWebviewListener(
"jetbrains/setColors",
async (data) => {
Object.entries(data).forEach(([key, value]) => {
document.body.style.setProperty(key, value);
document.documentElement.style.setProperty(key, value);
});
},
[],
);
useWebviewListener("docs/suggestions", async (data) => {
dispatch(updateDocsSuggestions(data));
});

View file

@ -26,7 +26,6 @@ module.exports = {
},
colors: {
lightgray: "#999998",
"vsc-background": "var(--vsc-background)", // "rgb(var(--vsc-background) / <alpha-value>)",
"vsc-input-background": "var(--vscode-input-background, rgb(45 45 45))",
"vsc-background": "var(--vscode-sideBar-background, rgb(30 30 30))",
"vsc-foreground": "var(--vscode-editor-foreground, #fff)",
@ -34,8 +33,8 @@ module.exports = {
"var(--vscode-editor-background, var(--vscode-sideBar-background, rgb(30 30 30)))",
"vsc-input-border": "var(--vscode-input-border, #999998)",
// I've moved a few over to the non-vsc-specific approach
// TODO move the rest
// Starting to make things less vsc-specific
// TODO make it all non-IDE-specific naming
"find-match-selected":
"var(--vscode-editor-findMatchHighlightBackground, rgba(255, 223, 0))",
"list-active": "var(--vscode-list-activeSelectionBackground, #1bbe84)",