дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 01:57:13 +02:00
fix(editor): show a followed plugin theme's colours and font styles in Color Scheme (#7474)
With a plugin theme active and the scheme on Theme default, Settings > Editor > Color Scheme resolved attributes and the preview against the built-in scheme instead of the plugin theme's tokens the editor paints with, so an italic comment showed unchecked and clearing it saved nothing. resolvedSchemeTokens / resolvedAttribute now take the followed theme's tokens under the user's overrides, the page shows the plugin theme's name, and Markdown comments follow the comment style variable. Closes #7453 Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
1 джерело
4e5ae49aa9
коміт
9abe3d7e3c
5 files changed
+77
-11
No files matched your search
@@ -82,7 +82,7 @@ const markdown = {
|
||||
".tok-string, .tok-string2": { color: "var(--syn-string)" },
|
||||
".tok-number, .tok-bool, .tok-atom": { color: "var(--syn-number)" },
|
||||
".tok-typeName, .tok-className, .tok-namespace": { color: "var(--syn-type)" },
|
||||
".tok-comment": { color: "var(--syn-comment)", fontStyle: "italic" },
|
||||
".tok-comment": { color: "var(--syn-comment)", fontStyle: "var(--syn-comment-italic, var(--syn-comment-style))" },
|
||||
".tok-meta, .tok-macroName": { color: "var(--syn-annotation)" },
|
||||
".tok-propertyName": { color: "var(--syn-property)" },
|
||||
".tok-variableName.tok-definition": { color: "var(--syn-function)" },
|
||||
|
||||
@@ -6,6 +6,7 @@ import { executeAction } from "@/platform/actions";
|
||||
import { CLEAR_COLOR, _setSchemeSource, resolvedAttribute } from "@/platform/colorScheme";
|
||||
import { setLocale } from "@/platform/i18n";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { usePlugins } from "@/features/plugins/store";
|
||||
import { DEFAULT_SETTINGS } from "../model/schema";
|
||||
import { languagePageId } from "../pages/editor/colorSchemeMeta";
|
||||
import { openSettings, stage, stagedValue, useSettingsDialog } from "../model/staging";
|
||||
@@ -308,6 +309,39 @@ describe("scheme attribute state", () => {
|
||||
expect(value("colorOverrides")).toEqual({ dark: { staticSymbol: { italic: false } } });
|
||||
});
|
||||
|
||||
it("shows a followed plugin theme's comment style and saves clearing it (#7453)", () => {
|
||||
_setSchemeSource(readFileSync("src/styles/tokens.css", "utf8"));
|
||||
const theme = {
|
||||
id: "one",
|
||||
name: "Plugin One",
|
||||
kind: "dark" as const,
|
||||
tokens: { "--syn-comment": "#5c6370", "--syn-comment-style": "italic" },
|
||||
};
|
||||
try {
|
||||
act(() => {
|
||||
usePlugins.setState({ activeTheme: { pluginId: "p", theme } });
|
||||
stage("editor.colorScheme", "global", "editor.colorScheme", "theme-default");
|
||||
});
|
||||
expect(screen.getByText("Follows the IDE theme: currently Plugin One.")).toBeInTheDocument();
|
||||
const preview = screen.getByLabelText("Color scheme preview");
|
||||
expect(preview.style.getPropertyValue("--syn-comment-style")).toBe("italic");
|
||||
act(() => fireEvent.click(preview.querySelector('span[style*="--syn-comment-italic"]')!));
|
||||
expect(screen.getByRole("textbox", { name: "Foreground hex" })).toHaveValue("#5c6370");
|
||||
const italic = screen.getByRole("checkbox", { name: "Italic" });
|
||||
expect(italic).toBeChecked();
|
||||
act(() => fireEvent.click(italic));
|
||||
expect(value("colorOverrides")).toEqual({ dark: { lineComment: { italic: false } } });
|
||||
expect(preview.style.getPropertyValue("--syn-comment-style")).toBe("normal");
|
||||
|
||||
// An explicitly chosen scheme replaces the plugin theme's colours, in the editor and here.
|
||||
act(() => stage("editor.colorScheme", "global", "editor.colorScheme", "dark"));
|
||||
expect(preview.style.getPropertyValue("--syn-comment")).not.toBe("#5c6370");
|
||||
} finally {
|
||||
usePlugins.setState({ activeTheme: null });
|
||||
_setSchemeSource("");
|
||||
}
|
||||
});
|
||||
|
||||
it("shows the red-green colours the editor uses and the setting behind them (#3851)", () => {
|
||||
_setSchemeSource(readFileSync("src/styles/tokens.css", "utf8"));
|
||||
try {
|
||||
|
||||
@@ -52,6 +52,7 @@ import { useContributions } from "@/workbench/contributions";
|
||||
import { parseIcls, SchemeParseError, importScheme, deleteScheme, exportIcls } from "@/platform/icls";
|
||||
import { tx, txPart, useTx } from "@/platform/i18n";
|
||||
import { selectPage } from "../../model/staging";
|
||||
import { usePlugins } from "@/features/plugins/store";
|
||||
|
||||
type Overrides = Record<string, Record<string, TextAttributesOverride>>;
|
||||
|
||||
@@ -134,9 +135,10 @@ function previewVars(
|
||||
customs: CustomColorSchemes,
|
||||
language?: string,
|
||||
redGreen = false,
|
||||
themeTokens?: Record<string, string>,
|
||||
): CSSProperties {
|
||||
const vars: Record<string, string> = {};
|
||||
const tokens = resolvedSchemeTokens(id, customs, redGreen, o);
|
||||
const tokens = resolvedSchemeTokens(id, customs, redGreen, o, themeTokens);
|
||||
for (const [k, v] of tokens)
|
||||
if (
|
||||
k.startsWith("--syn-") ||
|
||||
@@ -1779,6 +1781,10 @@ export function ColorSchemePage({
|
||||
crossPageReveal = null;
|
||||
});
|
||||
const id = effectiveScheme(scheme, undefined, customs);
|
||||
// A scheme that follows the IDE theme shows a plugin theme's colours, as the editor does (`schemeCss`).
|
||||
const pluginTheme = usePlugins((s) => s.activeTheme);
|
||||
const followed = pluginTheme && id !== scheme ? pluginTheme.theme : undefined;
|
||||
const themeTokens = followed?.tokens;
|
||||
const mine = overrides?.[id];
|
||||
/** Keys of every group containing an overridden attribute, so the blue marks the path to the root. */
|
||||
const modifiedKeys = useMemo(() => {
|
||||
@@ -1797,25 +1803,25 @@ export function ColorSchemePage({
|
||||
const attr = ATTRIBUTES.find((a) => a.id === selected);
|
||||
const language = attr?.language;
|
||||
const inherited = useMemo(
|
||||
() => (attr ? resolvedAttribute(id, attr.id, customs, redGreen) : {}),
|
||||
[id, attr, customs, redGreen],
|
||||
() => (attr ? resolvedAttribute(id, attr.id, customs, redGreen, themeTokens) : {}),
|
||||
[id, attr, customs, redGreen, themeTokens],
|
||||
);
|
||||
const vars = useMemo(() => {
|
||||
const next = {
|
||||
...previewVars(id, mine, customs, language, redGreen),
|
||||
...previewVars(id, mine, customs, language, redGreen, themeTokens),
|
||||
...fontWeightVars(weight, boldFontWeight),
|
||||
} as CSSProperties & Record<string, string>;
|
||||
// Console preview sits on the console background, not the editor surface.
|
||||
if (scopes[0] === "Console Colors" && next["--bg-console"]) next["--bg-editor"] = next["--bg-console"];
|
||||
return next;
|
||||
}, [id, mine, customs, language, weight, boldFontWeight, scopes, redGreen]);
|
||||
}, [id, mine, customs, language, weight, boldFontWeight, scopes, redGreen, themeTokens]);
|
||||
const baseVars = useMemo(
|
||||
() =>
|
||||
({
|
||||
...previewVars(id, mine, customs, undefined, redGreen),
|
||||
...previewVars(id, mine, customs, undefined, redGreen, themeTokens),
|
||||
...fontWeightVars(weight, boldFontWeight),
|
||||
}) as CSSProperties,
|
||||
[id, mine, customs, weight, boldFontWeight, redGreen],
|
||||
[id, mine, customs, weight, boldFontWeight, redGreen, themeTokens],
|
||||
);
|
||||
const update = (attrId: string, v: TextAttributesOverride | undefined) => {
|
||||
const next: Overrides = { ...(overrides ?? {}) };
|
||||
@@ -1967,7 +1973,9 @@ export function ColorSchemePage({
|
||||
</div>
|
||||
)}
|
||||
{scheme === "theme-default" && (
|
||||
<div className={styles.note}>{tx`Follows the IDE theme: currently ${txPart(schemeName)}.`}</div>
|
||||
<div
|
||||
className={styles.note}
|
||||
>{tx`Follows the IDE theme: currently ${txPart(followed?.name ?? schemeName)}.`}</div>
|
||||
)}
|
||||
{redGreen && (id === "dark" || id === "light") && (
|
||||
<div className={styles.note}>
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
_setSchemeSource,
|
||||
overrideDeclarations,
|
||||
resolvedAttribute,
|
||||
resolvedSchemeTokens,
|
||||
schemeAfterThemeChange,
|
||||
schemeCss,
|
||||
schemeTokens,
|
||||
@@ -394,6 +395,21 @@ describe("color schemes", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves a followed plugin theme's tokens under the user's overrides", () => {
|
||||
// A plugin theme with italic comments: the attribute shows italic, so clearing it saves an override.
|
||||
const theme = { "--syn-comment": "#5c6370", "--syn-comment-style": "italic", "--syn-doc-comment": "#98c379" };
|
||||
expect(resolvedAttribute("dark", "lineComment", {}, false, theme)).toMatchObject({
|
||||
foreground: "#5c6370",
|
||||
italic: true,
|
||||
});
|
||||
expect(resolvedAttribute("dark", "go.lineComment", {}, false, theme)).toMatchObject({ italic: true });
|
||||
expect(resolvedAttribute("dark", "docComment", {}, false, theme).foreground).toBe("#98c379");
|
||||
const tokens = resolvedSchemeTokens("dark", {}, false, { lineComment: { italic: false } }, theme);
|
||||
expect(tokens.get("--syn-comment")).toBe("#5c6370");
|
||||
expect(tokens.get("--syn-comment-style")).toBe("normal");
|
||||
expect(tokens.get("--syn-comment-italic")).toBe("normal");
|
||||
});
|
||||
|
||||
it("resolves package references from the editor foreground and emits their overrides", () => {
|
||||
for (const theme of ["light", "dark", "dark-hc"] as const) {
|
||||
expect(resolvedAttribute(theme, "packageReference").foreground).toBe(schemeTokens(theme).get("--fg-editor"));
|
||||
|
||||
@@ -879,17 +879,24 @@ export function listSchemes(customs: CustomColorSchemes = {}) {
|
||||
* A scheme's tokens with a custom scheme's attributes and then `overrides` applied; tokens that
|
||||
* tokens.css derives from an overridden one follow it unless they are overridden themselves. With
|
||||
* `redGreen`, a built-in scheme's red-green variant; a custom scheme keeps its parent's own colours.
|
||||
* `themeTokens` are those of a plugin theme the scheme follows, over the scheme's and under overrides.
|
||||
*/
|
||||
export function resolvedSchemeTokens(
|
||||
id: string,
|
||||
customs: CustomColorSchemes = {},
|
||||
redGreen = false,
|
||||
overrides?: Record<string, TextAttributesOverride>,
|
||||
themeTokens?: Record<string, string>,
|
||||
): Vars {
|
||||
const custom = customSchemes(customs)[id];
|
||||
const builtin = isBuiltinTheme(id);
|
||||
const base = builtin ? id : (custom?.parent ?? "light");
|
||||
const fixed: Vars = new Map([...overrideDeclarations(custom?.attributes), ...overrideDeclarations(overrides)]);
|
||||
// A plugin theme the scheme follows paints over the built-in one, as its stylesheet does in the editor.
|
||||
const fixed: Vars = new Map([
|
||||
...Object.entries(themeTokens ?? {}),
|
||||
...overrideDeclarations(custom?.attributes),
|
||||
...overrideDeclarations(overrides),
|
||||
]);
|
||||
return new Map(schemeTokens(base, source, redGreen && builtin, fixed));
|
||||
}
|
||||
|
||||
@@ -929,12 +936,13 @@ export function resolvedAttribute(
|
||||
attrId: string,
|
||||
customs: CustomColorSchemes = {},
|
||||
redGreen = false,
|
||||
themeTokens?: Record<string, string>,
|
||||
): TextAttributesOverride {
|
||||
const attr = ATTRIBUTES.find((a) => a.id === attrId);
|
||||
if (!attr) return {};
|
||||
const custom = customSchemes(customs)[id];
|
||||
const own = custom?.attributes[attr.id];
|
||||
const vars = resolvedSchemeTokens(id, customs, redGreen);
|
||||
const vars = resolvedSchemeTokens(id, customs, redGreen, undefined, themeTokens);
|
||||
if (attr.language) {
|
||||
const scoped = overrideDeclarations(custom?.attributes, attr.language);
|
||||
for (const [key, value] of scoped) vars.set(key, value);
|
||||
|
||||
Reference in new issue
Заблокувати користувача