Compare commits

...
Author SHA1 Message Date
l0ng-ai 32f4f63d2d fix(editor): give Darcula-based imported schemes Darcula's colours
An exported IntelliJ scheme lists only what differs from its parent. One based on
Darcula that leaves TEXT out took Islands Dark's background (#191a1c) instead of
Darcula's #2b2b2b. Attributes such a scheme doesn't name now come from Darcula,
both in Settings > Color Scheme import and in IntelliJ theme plugin import, and
exports write an empty value for an attribute they have nothing for, so the parent
can't show through on re-import. An imported scheme's gutter keeps its editor
background unless it sets its own.
2026-11-20 16:25:49 +08:00
8 changed files with 240 additions and 4 deletions

No files matched your search

+12
View File
@@ -187,6 +187,18 @@ describe("IntelliJ theme import", () => {
});
});
it("takes what a Darcula-based scheme leaves out from Darcula", () => {
const s = convertIcls(`<scheme name="Mine" version="142" parent_scheme="Darcula"><attributes>
<option name="DEFAULT_KEYWORD"><value><option name="FOREGROUND" value="ff8800"/></value></option>
<option name="DEFAULT_STRING"><value/></option>
</attributes></scheme>`);
expect(s.tokens["--bg-editor"]).toBe("#2b2b2b");
expect(s.tokens["--syn-keyword"]).toBe("#ff8800");
// An empty entry of its own replaces Darcula's colour.
expect(s.tokens["--syn-string"]).toBeUndefined();
expect(convertIcls(`<scheme name="I" parent_scheme="Islands Dark"></scheme>`).tokens).toEqual({});
});
it("only targets tokens that exist in tokens.css", () => {
const declared = new Set([...css.matchAll(/(--[a-z0-9-]+)\s*:/g)].map((m) => m[1]!));
// Read with a fallback by the editor (no tokens.css default), still themeable.
+104
View File
@@ -0,0 +1,104 @@
/**
* IntelliJ's bundled Darcula editor scheme (`DefaultColorSchemesManager.xml`) as `convertIcls` reads it.
* A theme's `.icls` with `parent_scheme="Darcula"` lists only what differs, and takes the rest from here.
*/
export const DARCULA_TOKENS: Readonly<Record<string, string>> = {
"--gutter-added": "#384c38",
"--gutter-modified": "#374752",
"--gutter-deleted": "#656e76",
"--caret": "#bbbbbb",
"--bg-current-line": "#323232",
"--bg-console": "#2b2b2b",
"--vcs-added": "#629755",
"--vcs-deleted": "#6c6c6c",
"--vcs-ignored": "#848504",
"--vcs-conflict": "#d5756c",
"--vcs-modified": "#6897bb",
"--vcs-untracked": "#d1675a",
"--border-indent-guide": "#373737",
"--fg-line-number": "#606366",
"--fg-line-number-current": "#a4a3a3",
"--border-method-separator": "#4d4d4d",
"--border-right-margin": "#4d4d4d",
"--border-indent-guide-active": "#505050",
"--bg-editor-selection": "#214283",
"--fg-whitespace": "#606060",
"--bg-breakpoint-line": "#3a2323",
"--ansi-black": "#000000",
"--terminal-ansi-black": "#000000",
"--ansi-blue": "#3993d4",
"--terminal-ansi-blue": "#3993d4",
"--ansi-bright-blue": "#1fb0ff",
"--terminal-ansi-bright-blue": "#1fb0ff",
"--ansi-cyan": "#00a3a3",
"--terminal-ansi-cyan": "#00a3a3",
"--ansi-bright-cyan": "#00e5e5",
"--terminal-ansi-bright-cyan": "#00e5e5",
"--ansi-bright-black": "#595959",
"--terminal-ansi-bright-black": "#595959",
"--ansi-white": "#808080",
"--terminal-ansi-white": "#808080",
"--ansi-green": "#5c962c",
"--terminal-ansi-green": "#5c962c",
"--ansi-bright-green": "#4fc414",
"--terminal-ansi-bright-green": "#4fc414",
"--ansi-magenta": "#a771bf",
"--terminal-ansi-magenta": "#a771bf",
"--ansi-bright-magenta": "#ed7eed",
"--terminal-ansi-bright-magenta": "#ed7eed",
"--ansi-red": "#f0524f",
"--terminal-ansi-red": "#f0524f",
"--ansi-bright-red": "#ff4050",
"--terminal-ansi-bright-red": "#ff4050",
"--ansi-bright-white": "#ffffff",
"--terminal-ansi-bright-white": "#ffffff",
"--ansi-yellow": "#a68a0d",
"--terminal-ansi-yellow": "#a68a0d",
"--ansi-bright-yellow": "#e5bf00",
"--terminal-ansi-bright-yellow": "#e5bf00",
"--syn-inline-value": "#666d75",
"--syn-constant": "#9876aa",
"--syn-doc-comment": "#629755",
"--syn-doc-comment-tag": "#629755",
"--syn-doc-markup": "#77b767",
"--syn-function-call": "#a9b7c6",
"--syn-function": "#ffc66d",
"--syn-variable": "#a9b7c6",
"--syn-property": "#9876aa",
"--syn-keyword": "#cc7832",
"--syn-comment": "#808080",
"--syn-annotation": "#bbb529",
"--syn-decorator": "#bbb529",
"--syn-number": "#6897bb",
"--syn-punct": "#a9b7c6",
"--syn-string": "#6a8759",
"--syn-escape": "#cc7832",
"--diff-conflict-stripe": "#8f5247",
"--diff-deleted": "#484a4a",
"--diff-deleted-stripe": "#656e76",
"--diff-inserted": "#294436",
"--diff-inserted-stripe": "#447152",
"--diff-modified": "#385570",
"--diff-modified-stripe": "#43698d",
"--syn-doc-comment-tag-value": "#8a653b",
"--wave-error": "#bc3f3c",
"--fg-fold-placeholder": "#8c8c8c",
"--bg-fold-placeholder": "#3a3a3a",
"--bg-identifier-under-caret": "#344134",
"--fg-inlay": "#787878",
"--bg-inlay": "#3b3b3b",
"--bg-matched-brace": "#3b514d",
"--fg-unused": "#72737a",
"--bg-search-result": "#155221",
"--fg-editor": "#a9b7c6",
"--bg-editor": "#2b2b2b",
"--bg-text-search-result": "#32593d",
"--syn-todo": "#a8c023",
"--bg-identifier-under-caret-write": "#40332b",
"--syn-rainbow-1": "#be7070",
"--syn-rainbow-2": "#3d7676",
"--syn-rainbow-3": "#be9970",
"--syn-rainbow-4": "#9d527c",
"--editor-error-decoration": "underline wavy #bc3f3c",
"--bg-editor-gutter": "#2b2b2b",
};
+9 -1
View File
@@ -4,11 +4,13 @@
* plugin into an OpenIDEA theme plugin package. The mapping covers the main
* keys only; anything unmapped keeps the built-in value of the base (`kind`).
*
* Pure functions without imports: Settings › Plugins › Import IntelliJ Theme
* Pure functions, importing only data: Settings › Plugins › Import IntelliJ Theme
* uses them on what the host read from the plugin (`plugin_read_intellij_theme`),
* and so does the command line (`scripts/theme/import-intellij-theme.ts`).
*/
import { DARCULA_TOKENS } from "./intellijDarcula.ts";
/** OpenIDEA token ← IntelliJ `ui` keys, first present wins. `*.prop` wildcards apply too. */
export const UI_KEYS: Record<string, string[]> = {
"--bg-app": ["Panel.background"],
@@ -358,6 +360,12 @@ export function convertIcls(xml: string): { name: string; dark: boolean | null;
tokens["--syn-comment-style"] = Number(parts.get("FONT_TYPE")) & 2 ? "italic" : "normal";
}
}
if (parent === "Darcula") {
// IntelliJ replaces a parent's attribute as a whole: what the file names, even empty or by baseAttributes, wins.
const keys = [...body.matchAll(/<option name="([^"]+)"/g)].map((m) => m[1]!);
const own = new Set(keys.flatMap((key) => (ICLS_ATTRIBUTES[key] ?? []).map(([, t]) => t)));
for (const [token, value] of Object.entries(DARCULA_TOKENS)) if (!own.has(token)) tokens[token] ??= value;
}
if (tokens["--wave-error"]) tokens["--editor-error-decoration"] = `underline wavy ${tokens["--wave-error"]}`;
if (tokens["--bg-editor"]) tokens["--bg-editor-gutter"] ??= tokens["--bg-editor"];
return { name, dark, tokens };
+16
View File
@@ -64,6 +64,22 @@ describe("color schemes", () => {
}
});
it("keeps an imported scheme's gutter on its editor background unless it sets its own", () => {
const customs = (gutter?: string) => ({
"custom-a": {
name: "A",
parent: "dark" as const,
attributes: { text: { background: "#2b2b2b" }, ...(gutter ? { gutter: { background: gutter } } : {}) },
},
});
expect(schemeCss("custom-a", undefined, document.documentElement, customs())).toContain(
"--bg-editor-gutter: #2b2b2b !important;",
);
expect(schemeCss("custom-a", undefined, document.documentElement, customs("#313335"))).toContain(
"--bg-editor-gutter: #313335 !important;",
);
});
it("offers a Go scheme page and scopes its overrides to Go editors", () => {
expect(ATTRIBUTES.find((a) => a.id === "go.constant")?.path).toEqual(["Go"]);
const css = schemeCss("dark", { dark: { "go.constant": { foreground: "#224466" } } });
+4 -1
View File
@@ -826,7 +826,10 @@ export function schemeCss(
}
// The editor surface follows the scheme, not the island colour of the UI theme.
const bg = tokens.get("--bg-editor") ?? tokens.get("--bg-island");
if (bg) decls.push(["--bg-editor", bg], ["--bg-editor-gutter", tokens.get("--bg-editor-gutter") ?? bg]);
// An imported scheme's gutter keeps its editor background unless it sets one of its own.
const custom = valid[id];
const gutter = custom ? (custom.attributes.gutter?.background ?? bg) : (tokens.get("--bg-editor-gutter") ?? bg);
if (bg) decls.push(["--bg-editor", bg], ["--bg-editor-gutter", gutter ?? bg]);
}
decls.push(...overrideDeclarations(overrides?.[id]));
const body = decls
+22 -1
View File
@@ -10,6 +10,7 @@ import {
schemeCss,
} from "./colorScheme";
import { deleteScheme, exportIcls, importScheme, parseIcls, SchemeParseError } from "./icls";
import { DARCULA_ATTRIBUTES } from "./iclsDarcula";
import { validateSettings } from "@/features/settings/model/schema";
import { colorSchemeItems } from "@/workbench/quickSwitch";
import { useProject } from "./project";
@@ -178,7 +179,7 @@ describe(".icls schemes", () => {
expect(fg("docCommentTagValue")).toBe("#e5c07b");
expect(fg("regexp")).toBe("#56b6c2");
// Superseded keys and DEFAULT_SEMICOLON are counted as skipped.
expect(scheme.attributes.operator).toBeUndefined();
expect(scheme.attributes.operator).toEqual(DARCULA_ATTRIBUTES.operator);
expect([applied, skipped]).toEqual([10, 6]);
});
@@ -405,6 +406,26 @@ describe(".icls schemes", () => {
expect(parseIcls(exportIcls(id, customs)).scheme.attributes.pyFString?.foreground).toBe("#808080");
});
it("takes what a Darcula-based scheme leaves out from Darcula, as IntelliJ does", () => {
const { scheme, applied } = parseIcls(`<scheme name="Mine" parent_scheme="Darcula"><attributes>
<option name="DEFAULT_KEYWORD"><value><option name="FOREGROUND" value="ff8800"/></value></option>
<option name="ERRORS_ATTRIBUTES"><value/></option>
<option name="DEFAULT_CONSTANT" baseAttributes="DEFAULT_IDENTIFIER"/>
</attributes></scheme>`);
expect(applied).toBe(1);
expect(scheme.parent).toBe("dark");
expect(scheme.attributes.text).toEqual({ foreground: "#a9b7c6", background: "#2b2b2b" });
expect(scheme.attributes.string?.foreground).toBe("#6a8759");
expect(scheme.attributes.keyword).toEqual({ foreground: "#ff8800", bold: false, italic: false });
// An entry of its own, even an empty one, replaces Darcula's.
expect(scheme.attributes.error).toBeUndefined();
expect(scheme.attributes.constant).toBeUndefined();
// The gutter keeps the editor's background, as in IntelliJ's new UI.
expect(scheme.attributes.gutter).toBeUndefined();
// Other parents keep the IDE's own base.
expect(parseIcls('<scheme name="I" parent_scheme="Islands Dark"></scheme>').scheme.attributes).toEqual({});
});
it("imports the global variable colour", () => {
const xml =
'<scheme name="G" parent_scheme="Darcula"><attributes><option name="DEFAULT_GLOBAL_VARIABLE"><value>' +
+9 -1
View File
@@ -10,6 +10,7 @@ import {
} from "./colorScheme";
import { isBuiltinTheme, themeKind } from "./themes";
import type { CustomColorScheme, CustomColorSchemes, TextAttributesOverride } from "./editorSettings";
import { DARCULA_ATTRIBUTES } from "./iclsDarcula";
// Many language keys share the editor's language-default tokens.
const ATTRIBUTE_NAMES: Record<string, string> = {
@@ -439,6 +440,12 @@ export function parseIcls(
}
}
const parentName = root.getAttribute("parent_scheme") ?? "";
// IntelliJ replaces a parent's attribute as a whole: any entry of the file, even an empty one or
// one only naming its baseAttributes, wins.
if (parentName === "Darcula") {
const own = new Set([...entries.keys()].flatMap((name) => (name ? targets(name) : [])));
for (const [id, value] of Object.entries(DARCULA_ATTRIBUTES)) if (!own.has(id)) attributes[id] ??= { ...value };
}
const bg = attributes.text?.background;
const rgb = bg ? [1, 3, 5].map((i) => parseInt(bg.slice(i, i + 2), 16)) : [255, 255, 255];
const dark = rgb[0]! * 0.299 + rgb[1]! * 0.587 + rgb[2]! * 0.114 < 128;
@@ -547,7 +554,8 @@ export function exportIcls(
if (isHexColor(v[field])) opts.push(`<option name="${key}" value="${exportColor(v[field]!)}" />`);
if (attr.token) opts.push(`<option name="FONT_TYPE" value="${(v.bold ? 1 : 0) + (v.italic ? 2 : 0)}" />`);
if (effect) opts.push(`<option name="EFFECT_TYPE" value="${effect}" />`);
if (opts.length) attributes.push(` <option name="${key}"><value>${opts.join("")}</value></option>`);
// An empty value keeps the parent scheme's attribute from showing through.
attributes.push(` <option name="${key}"><value>${opts.join("")}</value></option>`);
}
const parent = custom?.parent ?? (isBuiltinTheme(id) ? themeKind(id) : "dark");
return `<scheme name="${escapeXml(name)}" version="142" parent_scheme="${parent === "dark" ? "Darcula" : "Default"}">\n <colors>\n${colors.join("\n")}\n </colors>\n <attributes>\n${attributes.join("\n")}\n </attributes>\n</scheme>\n`;
+64
View File
@@ -0,0 +1,64 @@
import type { TextAttributesOverride } from "./editorSettings";
/**
* IntelliJ's bundled Darcula editor scheme (`DefaultColorSchemesManager.xml`) as read by `parseIcls`.
* An exported scheme lists only what differs from its parent, so one with `parent_scheme="Darcula"`
* takes every attribute it leaves out from here (background `#2b2b2b`, not Islands Dark's). Its classic
* GUTTER_BACKGROUND is left out: the gutter keeps the editor's background, as in IntelliJ's new UI.
*/
export const DARCULA_ATTRIBUTES: Readonly<Record<string, TextAttributesOverride>> = {
caret: { foreground: "#bbbbbb" },
caretRow: { background: "#323232" },
consoleBackground: { background: "#2b2b2b" },
indentGuide: { foreground: "#373737" },
lineNumber: { foreground: "#606366" },
lineNumberCaret: { foreground: "#a4a3a3" },
methodSeparator: { foreground: "#4d4d4d" },
rightMargin: { foreground: "#4d4d4d" },
selection: { background: "#214283" },
whitespaces: { foreground: "#606060" },
ansiBlack: { foreground: "#000000" },
ansiBlue: { foreground: "#3993d4" },
ansiBrightBlue: { foreground: "#1fb0ff" },
ansiCyan: { foreground: "#00a3a3" },
ansiBrightCyan: { foreground: "#00e5e5" },
ansiBrightBlack: { foreground: "#595959" },
ansiWhite: { foreground: "#808080" },
ansiGreen: { foreground: "#5c962c" },
ansiBrightGreen: { foreground: "#4fc414" },
ansiMagenta: { foreground: "#a771bf" },
ansiBrightMagenta: { foreground: "#ed7eed" },
ansiRed: { foreground: "#f0524f" },
ansiBrightRed: { foreground: "#ff4050" },
ansiBrightWhite: { foreground: "#ffffff" },
ansiYellow: { foreground: "#a68a0d" },
ansiBrightYellow: { foreground: "#e5bf00" },
constant: { bold: false, italic: true, foreground: "#9876aa" },
docComment: { bold: false, italic: true, foreground: "#629755" },
docCommentTag: { bold: true, italic: true, foreground: "#629755", effectColor: "#629755", effect: "underline" },
docCommentMarkup: { bold: false, italic: false, foreground: "#77b767" },
functionCall: { bold: false, italic: false },
functionDeclaration: { bold: false, italic: false, foreground: "#ffc66d" },
identifier: { bold: false, italic: false, foreground: "#a9b7c6" },
field: { bold: false, italic: false, foreground: "#9876aa" },
invalid: { bold: false, italic: false, foreground: "#6a8759", effectColor: "#ff0000", effect: "wave" },
keyword: { bold: false, italic: false, foreground: "#cc7832" },
lineComment: { bold: false, italic: false, foreground: "#808080" },
metadata: { bold: false, italic: false, foreground: "#bbb529" },
number: { bold: false, italic: false, foreground: "#6897bb" },
operator: { bold: false, italic: false },
string: { bold: false, italic: false, foreground: "#6a8759" },
escape: { bold: false, italic: false, foreground: "#cc7832" },
docCommentTagValue: { bold: false, italic: false, foreground: "#8a653b" },
error: { effectColor: "#bc3f3c", effect: "wave" },
folded: { foreground: "#8c8c8c", background: "#3a3a3a" },
identifierUnderCaret: { background: "#344134" },
inlay: { foreground: "#787878", background: "#3b3b3b" },
matchedBrace: { background: "#3b514d" },
unused: { foreground: "#72737a" },
searchResult: { background: "#155221" },
text: { foreground: "#a9b7c6", background: "#2b2b2b" },
searchResultCurrent: { background: "#32593d" },
todo: { bold: false, italic: true, foreground: "#a8c023" },
identifierUnderCaretWrite: { background: "#40332b" },
};