From 32f4f63d2d1bb3c385500db4b6b36d358917e32c Mon Sep 17 00:00:00 2001
From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com>
Date: Fri, 20 Nov 2026 15:04:19 +0800
Subject: [PATCH] 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.
---
scripts/theme/theme.test.ts | 12 +++
src/features/plugins/intellijDarcula.ts | 104 ++++++++++++++++++++++++
src/features/plugins/intellijTheme.ts | 10 ++-
src/platform/colorScheme.test.ts | 16 ++++
src/platform/colorScheme.ts | 5 +-
src/platform/icls.test.ts | 23 +++++-
src/platform/icls.ts | 10 ++-
src/platform/iclsDarcula.ts | 64 +++++++++++++++
8 files changed, 240 insertions(+), 4 deletions(-)
create mode 100644 src/features/plugins/intellijDarcula.ts
create mode 100644 src/platform/iclsDarcula.ts
diff --git a/scripts/theme/theme.test.ts b/scripts/theme/theme.test.ts
index 67ee3b3883..10710bf76d 100644
--- a/scripts/theme/theme.test.ts
+++ b/scripts/theme/theme.test.ts
@@ -187,6 +187,18 @@ describe("IntelliJ theme import", () => {
});
});
+ it("takes what a Darcula-based scheme leaves out from Darcula", () => {
+ const s = convertIcls(`
+
+
+ `);
+ 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(``).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.
diff --git a/src/features/plugins/intellijDarcula.ts b/src/features/plugins/intellijDarcula.ts
new file mode 100644
index 0000000000..7f3708e81d
--- /dev/null
+++ b/src/features/plugins/intellijDarcula.ts
@@ -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> = {
+ "--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",
+};
diff --git a/src/features/plugins/intellijTheme.ts b/src/features/plugins/intellijTheme.ts
index 67eeddd32e..07d2874a8f 100644
--- a/src/features/plugins/intellijTheme.ts
+++ b/src/features/plugins/intellijTheme.ts
@@ -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 = {
"--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(/
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 };
diff --git a/src/platform/colorScheme.test.ts b/src/platform/colorScheme.test.ts
index 3286f10fda..394fee66c6 100644
--- a/src/platform/colorScheme.test.ts
+++ b/src/platform/colorScheme.test.ts
@@ -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" } } });
diff --git a/src/platform/colorScheme.ts b/src/platform/colorScheme.ts
index 06655d1fb6..5a3f7c87ce 100644
--- a/src/platform/colorScheme.ts
+++ b/src/platform/colorScheme.ts
@@ -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
diff --git a/src/platform/icls.test.ts b/src/platform/icls.test.ts
index 532199a520..44e3cf0257 100644
--- a/src/platform/icls.test.ts
+++ b/src/platform/icls.test.ts
@@ -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(`
+
+
+
+ `);
+ 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.attributes).toEqual({});
+ });
+
it("imports the global variable colour", () => {
const xml =
'
' +
diff --git a/src/platform/icls.ts b/src/platform/icls.ts
index b1adc1527d..4328b5b5dd 100644
--- a/src/platform/icls.ts
+++ b/src/platform/icls.ts
@@ -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 = {
@@ -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(`
`);
if (attr.token) opts.push(`
`);
if (effect) opts.push(`
`);
- if (opts.length) attributes.push(`
${opts.join("")}
`);
+ // An empty value keeps the parent scheme's attribute from showing through.
+ attributes.push(`