feat(color-scheme): foreground for Identifier under caret (#4135)

Identifier under caret and Identifier under caret (write) can now set a Foreground, as in IDEA; imported .icls schemes carry it too. The highlight mark wraps the syntax and semantic token spans, so the colour is applied with the inherited -webkit-text-fill-color: unset, the declaration drops and tokens keep their syntax colours; find matches, selection, links, inlay hints and fold placeholders keep their own colours. Multi-line highlights colour only the highlighted text, not the indent.

Closes #4109

Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com>
This commit is contained in:
LU XIANGRUI
2026-11-18 16:37:49 +08:00
committed by GitHub
co-authored by wildcatDownstairs
parent d7351dca1d
commit 923325aeae
19 changed files with 189 additions and 12 deletions
+4 -1
View File
@@ -238,7 +238,8 @@ The full table is `UI_KEYS` in
| `--syn-tag`, `--syn-attribute`, `--syn-todo`, `--syn-invalid` | `DEFAULT_TAG`, `DEFAULT_ATTRIBUTE`, `TODO_DEFAULT_ATTRIBUTES`, `BAD_CHARACTER` |
| `--syn-rainbow-1` … `--syn-rainbow-5` (Semantic highlighting) | `RAINBOW_COLOR1` … `RAINBOW_COLOR5` |
| `--wave-error`, `--wave-warning` | `ERRORS_ATTRIBUTES`, `WARNING_ATTRIBUTES` (effect colour) |
| `--bg-matched-brace`, `--bg-identifier-under-caret` | `MATCHED_BRACE_ATTRIBUTES`, `IDENTIFIER_UNDER_CARET_ATTRIBUTES` |
| `--bg-matched-brace`, `--bg-identifier-under-caret`, `--fg-identifier-under-caret` | `MATCHED_BRACE_ATTRIBUTES`, `IDENTIFIER_UNDER_CARET_ATTRIBUTES` |
| `--bg-identifier-under-caret-write`, `--fg-identifier-under-caret-write` | `WRITE_IDENTIFIER_UNDER_CARET_ATTRIBUTES` |
| `--bg-text-search-result`, `--bg-search-result` | `TEXT_SEARCH_RESULT_ATTRIBUTES`, `SEARCH_RESULT_ATTRIBUTES` |
| `--syn-self`, `--syn-keyword-arg`, `--syn-docstring`, `--syn-predefined` | `PY.SELF_PARAMETER`, `PY.KEYWORD_ARGUMENT`, `PY.DOC_COMMENT`, `PY.BUILTIN_NAME` |
| `--ansi-*` | `CONSOLE_*_OUTPUT` (`CONSOLE_DARKGRAY_OUTPUT` is bright black, `CONSOLE_GRAY_OUTPUT` white) |
@@ -519,6 +520,8 @@ conventionally go in the theme file, groups marked _editor scheme_ in the scheme
| `--fg-unused` | `#6f737a` | `#8c8c8c` |
| `--bg-identifier-under-caret` | `#373b39` | `#edebfc` |
| `--bg-identifier-under-caret-write` | `#402f33` | `#fce8f4` |
| `--fg-identifier-under-caret` | `inherit` | `inherit` |
| `--fg-identifier-under-caret-write` | `inherit` | `inherit` |
| `--fg-inlay` | `#868a91` | `#73767c` |
| `--bg-inlay` | `#393b40` | `#00000012` |
| `--wave-error` | `#fa6675` | `#f50000` |
+4 -1
View File
@@ -211,7 +211,8 @@ pnpm theme:import-intellij path/to/MyTheme.theme.json path/to/MyTheme.icls --out
| `--syn-tag`, `--syn-attribute`, `--syn-todo`, `--syn-invalid` | `DEFAULT_TAG`, `DEFAULT_ATTRIBUTE`, `TODO_DEFAULT_ATTRIBUTES`, `BAD_CHARACTER` |
| `--syn-rainbow-1` … `--syn-rainbow-5`(语义高亮) | `RAINBOW_COLOR1` … `RAINBOW_COLOR5` |
| `--wave-error`, `--wave-warning` | `ERRORS_ATTRIBUTES`, `WARNING_ATTRIBUTES`(效果颜色) |
| `--bg-matched-brace`, `--bg-identifier-under-caret` | `MATCHED_BRACE_ATTRIBUTES`, `IDENTIFIER_UNDER_CARET_ATTRIBUTES` |
| `--bg-matched-brace`, `--bg-identifier-under-caret`, `--fg-identifier-under-caret` | `MATCHED_BRACE_ATTRIBUTES`, `IDENTIFIER_UNDER_CARET_ATTRIBUTES` |
| `--bg-identifier-under-caret-write`, `--fg-identifier-under-caret-write` | `WRITE_IDENTIFIER_UNDER_CARET_ATTRIBUTES` |
| `--bg-text-search-result`, `--bg-search-result` | `TEXT_SEARCH_RESULT_ATTRIBUTES`, `SEARCH_RESULT_ATTRIBUTES` |
| `--syn-self`, `--syn-keyword-arg`, `--syn-docstring`, `--syn-predefined` | `PY.SELF_PARAMETER`, `PY.KEYWORD_ARGUMENT`, `PY.DOC_COMMENT`, `PY.BUILTIN_NAME` |
| `--ansi-*` | `CONSOLE_*_OUTPUT`(`CONSOLE_DARKGRAY_OUTPUT` 为亮黑,`CONSOLE_GRAY_OUTPUT` 为白色) |
@@ -485,6 +486,8 @@ VS Code 主题(扩展中的 `themes/*.json`)包含 `type`(`dark` / `light`
| `--fg-unused` | `#6f737a` | `#8c8c8c` |
| `--bg-identifier-under-caret` | `#373b39` | `#edebfc` |
| `--bg-identifier-under-caret-write` | `#402f33` | `#fce8f4` |
| `--fg-identifier-under-caret` | `inherit` | `inherit` |
| `--fg-identifier-under-caret-write` | `inherit` | `inherit` |
| `--fg-inlay` | `#868a91` | `#73767c` |
| `--bg-inlay` | `#393b40` | `#00000012` |
| `--wave-error` | `#fa6675` | `#f50000` |
@@ -104,6 +104,8 @@
"--fg-deprecated": "#8c8f95",
"--bg-identifier-under-caret": "#2e353f",
"--bg-identifier-under-caret-write": "#402f33",
"--fg-identifier-under-caret": "inherit",
"--fg-identifier-under-caret-write": "inherit",
"--fg-inlay": "#75869d",
"--bg-inlay": "#303944",
"--wave-typo": "#59a869",
+5 -2
View File
@@ -232,7 +232,8 @@ The full table is `UI_KEYS` in [`src/features/plugins/intellijTheme.ts`](../src/
| `--syn-tag`, `--syn-attribute`, `--syn-todo`, `--syn-invalid` | `DEFAULT_TAG`, `DEFAULT_ATTRIBUTE`, `TODO_DEFAULT_ATTRIBUTES`, `BAD_CHARACTER` |
| `--syn-rainbow-1` … `--syn-rainbow-5` (Semantic highlighting, rainbow indent guides) | `RAINBOW_COLOR1` … `RAINBOW_COLOR5` |
| `--wave-error`, `--wave-warning` | `ERRORS_ATTRIBUTES`, `WARNING_ATTRIBUTES` (effect colour) |
| `--bg-matched-brace`, `--bg-identifier-under-caret` | `MATCHED_BRACE_ATTRIBUTES`, `IDENTIFIER_UNDER_CARET_ATTRIBUTES` |
| `--bg-matched-brace`, `--bg-identifier-under-caret`, `--fg-identifier-under-caret` | `MATCHED_BRACE_ATTRIBUTES`, `IDENTIFIER_UNDER_CARET_ATTRIBUTES` |
| `--bg-identifier-under-caret-write`, `--fg-identifier-under-caret-write` | `WRITE_IDENTIFIER_UNDER_CARET_ATTRIBUTES` |
| `--bg-text-search-result`, `--bg-search-result` | `TEXT_SEARCH_RESULT_ATTRIBUTES`, `SEARCH_RESULT_ATTRIBUTES` |
| `--syn-self`, `--syn-keyword-arg`, `--syn-docstring`, `--syn-predefined` | `PY.SELF_PARAMETER`, `PY.KEYWORD_ARGUMENT`, `PY.DOC_COMMENT`, `PY.BUILTIN_NAME` |
| `--ansi-*` | `CONSOLE_*_OUTPUT` (`CONSOLE_DARKGRAY_OUTPUT` is bright black, `CONSOLE_GRAY_OUTPUT` white) |
@@ -332,7 +333,7 @@ a token.
<!-- BEGIN GENERATED TOKEN REFERENCE: pnpm gen:theme-docs -->
269 themeable tokens: 125 in the UI theme file, 144 in the editor colour scheme file.
271 themeable tokens: 125 in the UI theme file, 146 in the editor colour scheme file.
### Surfaces (UI theme)
@@ -528,6 +529,8 @@ a token.
| `--fg-deprecated` | `#8c8f95` | `#6c707e` |
| `--bg-identifier-under-caret` | `#373b39` | `#edebfc` |
| `--bg-identifier-under-caret-write` | `#402f33` | `#fce8f4` |
| `--fg-identifier-under-caret` | `inherit` | `inherit` |
| `--fg-identifier-under-caret-write` | `inherit` | `inherit` |
| `--fg-inlay` | `#868a91` | `#73767c` |
| `--bg-inlay` | `#393b40` | `#00000012` |
| `--wave-error` | `#fa6675` | `#f50000` |
+17
View File
@@ -170,6 +170,23 @@ describe("IntelliJ theme import", () => {
});
});
it("maps the caret identifier foregrounds (#4109)", () => {
const s = convertIcls(`<scheme name="Caret" version="142" parent_scheme="Darcula"><attributes>
<option name="IDENTIFIER_UNDER_CARET_ATTRIBUTES"><value>
<option name="FOREGROUND" value="aa0000" /><option name="BACKGROUND" value="220000" />
</value></option>
<option name="WRITE_IDENTIFIER_UNDER_CARET_ATTRIBUTES"><value>
<option name="FOREGROUND" value="00aa00" /><option name="BACKGROUND" value="002200" />
</value></option>
</attributes></scheme>`);
expect(s.tokens).toMatchObject({
"--fg-identifier-under-caret": "#aa0000",
"--bg-identifier-under-caret": "#220000",
"--fg-identifier-under-caret-write": "#00aa00",
"--bg-identifier-under-caret-write": "#002200",
});
});
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.
+45 -1
View File
@@ -1,10 +1,11 @@
import { afterEach, describe, expect, it } from "vitest";
import { EditorSelection, EditorState, Prec } from "@codemirror/state";
import { Decoration, EditorView } from "@codemirror/view";
import { Decoration, EditorView, WidgetType } from "@codemirror/view";
import { setSearchQuery } from "@codemirror/search";
import { StreamLanguage } from "@codemirror/language";
import { literalKindAt } from "./literals";
import { selectionMarks } from "./selectionMarks";
import { findStyles, markWidgetStyles } from "./theme";
import {
countMatches,
findResultLines,
@@ -41,6 +42,49 @@ function make(doc: string, o: Partial<FindOptions>, scope?: { from: number; to:
const sel = (v: EditorView) => [v.state.selection.main.from, v.state.selection.main.to];
class TextWidget extends WidgetType {
toDOM() {
const el = document.createElement("span");
el.className = "widget";
el.textContent = "hint";
return el;
}
}
describe("widgets inside find matches", () => {
it.each([
["before the cursor side", Decoration.widget({ widget: new TextWidget(), side: -1 }).range(3)],
["after the cursor side", Decoration.widget({ widget: new TextWidget(), side: 1 }).range(3)],
["replacing text", Decoration.replace({ widget: new TextWidget() }).range(2, 4)],
])("keep their own colour %s", (_name, widget) => {
const view = new EditorView({
parent: document.body,
doc: "Session",
extensions: [
// At the top precedence, as only then does the match wrap the widget.
Prec.highest(EditorView.decorations.of(Decoration.set(widget))),
findExtension(),
],
});
views.push(view);
view.dispatch({
effects: [
setFindOpen.of(true),
setSearchQuery.of(
makeQuery({ search: "Session", caseSensitive: true, wholeWord: false, regexp: false, replace: "" }),
),
],
});
const el = view.contentDOM.querySelector<HTMLElement>(".cm-openidea-findMatch .widget")!;
// Browsers reflect this property to the attribute; jsdom does not.
el.setAttribute("contenteditable", el.contentEditable);
expect(el.matches(Object.keys(markWidgetStyles)[0]!)).toBe(true);
expect(Object.values(markWidgetStyles)[0]!.WebkitTextFillColor).toBe("currentcolor");
// A text fill of `--fg-search-match` here would reach every widget in the match.
expect(findStyles[".cm-openidea-findMatch"].WebkitTextFillColor).toBe("currentcolor");
});
});
describe("find backgrounds", () => {
it.each([
["semantic", Prec.highest],
+1
View File
@@ -46,6 +46,7 @@ const theme = EditorView.baseTheme({
boxDecorationBreak: "clone",
// Unset (the default `inherit`): the declaration drops and the syntax colours show through.
color: "var(--fg-editor-selection)",
WebkitTextFillColor: "var(--fg-editor-selection)",
},
"&.cm-focused .cm-openidea-selected": {
"--openidea-selected-bg": "var(--editor-selection, var(--bg-editor-selection))",
+10
View File
@@ -24,6 +24,8 @@ export const findStyles = {
".cm-openidea-findMatch": {
backgroundColor: "var(--editor-search)",
color: "var(--fg-search-match, inherit)",
// Its own colour, over the text fill of an identifier highlight around the match.
WebkitTextFillColor: "currentcolor",
borderRadius: "2px",
},
".cm-openidea-findExcluded": {
@@ -40,6 +42,11 @@ export const findStyles = {
},
};
/** Marks colour text with an inherited text fill; widgets inside them keep their own colours. */
export const markWidgetStyles = {
'.cm-content [contenteditable="false"]': { WebkitTextFillColor: "currentcolor" },
};
/** The caret and Settings › Editor › General › Appearance caret options (`caretExtension`), also for viewers. */
export const caretStyles = {
".cm-cursor, .cm-dropCursor": {
@@ -219,6 +226,8 @@ export const openideaTheme = EditorView.theme({
".cm-selectionMatch": {
backgroundColor: "var(--bg-identifier-under-caret, color-mix(in srgb, var(--fg) 9%, transparent))",
},
// IDEA paints these with IDENTIFIER_UNDER_CARET_ATTRIBUTES, except the selection itself.
".cm-selectionMatch:not(.cm-selectionMatch-main)": { WebkitTextFillColor: "var(--fg-identifier-under-caret)" },
// IDEA's MATCHED_BRACE_ATTRIBUTES (bold in dark schemes only) and MATCHED_TAG_NAME (never bold).
".cm-matchingBracket, &.cm-focused .cm-matchingBracket": {
backgroundColor: "var(--editor-brace)",
@@ -343,6 +352,7 @@ export const openideaTheme = EditorView.theme({
// Find in file (cm/find.ts)
...findStyles,
...markWidgetStyles,
// Find in Files preview matches (search/find/parts.tsx)
".cm-openidea-searchResult": { backgroundColor: "var(--bg-search-result)" },
+7 -1
View File
@@ -1240,6 +1240,12 @@ const marks = {
read: Decoration.mark({ class: KIND_CLASS.read }),
write: Decoration.mark({ class: KIND_CLASS.write }),
};
/** The text a multi-line highlight paints with line backgrounds: a line class would also colour its indent. */
const lineText = {
text: Decoration.mark({ class: "cm-lsp-occurrence-text" }),
read: Decoration.mark({ class: "cm-lsp-occurrence-text" }),
write: Decoration.mark({ class: "cm-lsp-occurrence-text cm-lsp-occurrence-text-write" }),
};
const fullLines = {
text: Decoration.line({ class: KIND_CLASS.text }),
read: Decoration.line({ class: KIND_CLASS.read }),
@@ -1266,7 +1272,7 @@ function highlightDeco(doc: Text, tabSize: number, items: readonly HighlightItem
class: i.kind === "write" ? "cm-lsp-occurrence-tail cm-lsp-occurrence-tail-write" : "cm-lsp-occurrence-tail",
attributes: { style: `--lsp-occurrence-from: calc(${LINE_INSET}px + ${col}ch)` },
});
out.push(tail.range(first.from));
out.push(tail.range(first.from), lineText[i.kind].range(i.from, last.from));
for (let n = first.number + 1; n < last.number; n++) out.push(fullLines[i.kind].range(doc.line(n).from));
if (i.to > last.from) out.push(marks[i.kind].range(last.from, i.to));
}
+7
View File
@@ -314,6 +314,7 @@ export const lspTheme = EditorView.theme({
// --- navigation ---------------------------------------------------------
".cm-lsp-link": {
color: "var(--link)",
WebkitTextFillColor: "currentcolor",
textDecoration: "underline",
textUnderlineOffset: "2px",
cursor: "pointer",
@@ -325,6 +326,12 @@ export const lspTheme = EditorView.theme({
"--lsp-occurrence-bg": "var(--bg-identifier-under-caret-write, color-mix(in srgb, var(--danger) 12%, transparent))",
},
".cm-lsp-occurrence": { backgroundColor: "var(--lsp-occurrence-bg)" },
// Text fill, not `color`: it reaches the syntax and semantic spans nested inside, and with the
// variable unset the declaration drops, so they keep their own colours.
"span.cm-lsp-occurrence, .cm-lsp-occurrence-text": { WebkitTextFillColor: "var(--fg-identifier-under-caret)" },
"span.cm-lsp-occurrence-write, .cm-lsp-occurrence-text-write": {
WebkitTextFillColor: "var(--fg-identifier-under-caret-write)",
},
// First line of a highlight over several lines: from its start column to the right edge,
// over the line's own background (the caret row's).
".cm-lsp-occurrence-tail": {
+20
View File
@@ -72,6 +72,26 @@ describe("highlights of the element at the caret", () => {
expect(lines(v)[4]!.className).not.toContain("cm-lsp-occurrence");
});
it.each([
["text", ""],
["write", "-write"],
] as const)(
"marks exactly the text of a %s highlight over several lines for its foreground",
async (kind, suffix) => {
cmd.lspDocumentHighlights.mockImplementation(() => ok([{ range: range(1, 4, 3, 13), kind }]));
const v = editor(at(1, 4));
highlightUsages(v);
await vi.waitFor(() => expect(v.contentDOM.querySelector(".cm-lsp-occurrence-text")).not.toBeNull());
const text = (line: number) =>
[...lines(v)[line]!.querySelectorAll(`.cm-lsp-occurrence-text${suffix}`)].map((e) => e.textContent).join("");
// Not the indent before the start column; the last line is the highlight's own mark.
expect(text(1)).toBe("return a");
expect(text(2)).toBe(" .b()");
expect(text(3)).toBe("");
expect(lines(v)[3]!.querySelector(`span.cm-lsp-occurrence${suffix}`)?.textContent).toBe(" .c();");
},
);
it("keeps a single-line highlight on its text", async () => {
cmd.lspDocumentHighlights.mockImplementation(() => ok([{ range: range(6, 11, 6, 12), kind: "read" }]));
const v = editor(at(6, 11));
+8 -2
View File
@@ -180,8 +180,14 @@ export const ICLS_ATTRIBUTES: Record<string, Array<[Part, string]>> = {
MATCHED_BRACE_ATTRIBUTES: [["BACKGROUND", "--bg-matched-brace"]],
SEARCH_RESULT_ATTRIBUTES: [["BACKGROUND", "--bg-search-result"]],
TEXT_SEARCH_RESULT_ATTRIBUTES: [["BACKGROUND", "--bg-text-search-result"]],
IDENTIFIER_UNDER_CARET_ATTRIBUTES: [["BACKGROUND", "--bg-identifier-under-caret"]],
WRITE_IDENTIFIER_UNDER_CARET_ATTRIBUTES: [["BACKGROUND", "--bg-identifier-under-caret-write"]],
IDENTIFIER_UNDER_CARET_ATTRIBUTES: [
["FOREGROUND", "--fg-identifier-under-caret"],
["BACKGROUND", "--bg-identifier-under-caret"],
],
WRITE_IDENTIFIER_UNDER_CARET_ATTRIBUTES: [
["FOREGROUND", "--fg-identifier-under-caret-write"],
["BACKGROUND", "--bg-identifier-under-caret-write"],
],
FOLDED_TEXT_ATTRIBUTES: [
["FOREGROUND", "--fg-fold-placeholder"],
["BACKGROUND", "--bg-fold-placeholder"],
@@ -122,10 +122,10 @@ describe("theme tokens", () => {
* Tokens the palette themes (Solarized, One) take from their light / dark base
* on purpose: colours the user assigns (project and data source colours), the
* platform's caption close and macOS window buttons, the tint strength, and
* the selection foreground, whose base default preserves syntax colours.
* the selection and caret identifier foregrounds, whose base default preserves syntax colours.
*/
const INHERITED_FROM_BASE =
/^--(project-color-|db-color-|file-color-|caption-close-|fg-caption-close-|tint-strength$|file-tint-strength$|fg-editor-selection$)/;
/^--(project-color-|db-color-|file-color-|caption-close-|fg-caption-close-|tint-strength$|file-tint-strength$|fg-editor-selection$|fg-identifier-under-caret(-write)?$)/;
describe("palette themes", () => {
const ISLANDS = ["light", "dark", "dark-hc"];
+2 -1
View File
@@ -42,7 +42,7 @@ import { overviewLane } from "@/editor/core/cm/lanes";
import { LINE_INSET } from "@/editor/core/cm/lineInset";
import { caretExtension } from "@/editor/core/cm/prefs";
import { fontExtension, tooltipBounds } from "@/editor/core/cm/setup";
import { caretStyles, findLocals, findStyles, overviewStyles } from "@/editor/core/cm/theme";
import { caretStyles, findLocals, findStyles, markWidgetStyles, overviewStyles } from "@/editor/core/cm/theme";
import { editorPrefs } from "@/platform/editorSettings";
import { useProject } from "@/platform/project";
import { getDiffInsights, hasInnerFragments } from "./diffOptions";
@@ -413,6 +413,7 @@ export const viewerTheme = EditorView.theme(
".cm-panels": { backgroundColor: "var(--bg-elev)", color: "var(--fg)" },
".cm-searchMatch": { backgroundColor: "color-mix(in srgb, var(--accent) 22%, transparent)" },
...findStyles,
...markWidgetStyles,
},
{ dark: true },
);
+15
View File
@@ -3,6 +3,7 @@ import { beforeAll, describe, expect, it } from "vitest";
import {
ATTRIBUTES,
CLEAR_COLOR,
SCHEMES,
_setSchemeSource,
overrideDeclarations,
resolvedAttribute,
@@ -221,6 +222,20 @@ describe("color schemes", () => {
);
});
it.each([
["identifierUnderCaret", "--fg-identifier-under-caret"],
["identifierUnderCaretWrite", "--fg-identifier-under-caret-write"],
])("lets %s set a foreground over the syntax colours (#4109)", (id, token) => {
expect(ATTRIBUTES.find((a) => a.id === id)?.fg).toBe(token);
// The `inherit` default is no colour: every built-in scheme keeps the syntax colours.
for (const scheme of SCHEMES) expect(resolvedAttribute(scheme.id, id).foreground).toBeUndefined();
expect(schemeCss("dark", { dark: { [id]: { foreground: "#112233" } } })).toContain(`${token}: #112233 !important`);
// Unticked, the syntax colours show again rather than one flat default text colour.
expect(schemeCss("dark", { dark: { [id]: { foreground: CLEAR_COLOR } } })).toContain(
`${token}: inherit !important`,
);
});
// #3851: the editor showed the red-green colours while Color Scheme showed the plain ones.
it("resolves the red-green variant of the bundled schemes only", () => {
const rg = (id: Parameters<typeof schemeTokens>[0], name: string) => schemeTokens(id, undefined, true).get(name);
+8 -1
View File
@@ -25,6 +25,8 @@ export interface AttributeDef {
path: string[];
/** CSS variable of the foreground / background / effect colour, if editable. */
fg?: string;
/** `fg` paints over the syntax colours: without one, they show through. */
fgOverlay?: true;
bg?: string;
effect?: string;
/** Syntax token: bold / italic / background / effect come from `--syn-<token>-*`. */
@@ -112,12 +114,16 @@ const BASE_ATTRIBUTES: readonly AttributeDef[] = [
id: "identifierUnderCaret",
name: "Identifier under caret",
path: ["General", "Code"],
fg: "--fg-identifier-under-caret",
fgOverlay: true,
bg: "--bg-identifier-under-caret",
},
{
id: "identifierUnderCaretWrite",
name: "Identifier under caret (write)",
path: ["General", "Code"],
fg: "--fg-identifier-under-caret-write",
fgOverlay: true,
bg: "--bg-identifier-under-caret-write",
},
{ id: "inlay", name: "Inlay hints", path: ["General", "Code"], fg: "--fg-inlay", bg: "--bg-inlay" },
@@ -606,7 +612,8 @@ export function overrideDeclarations(
if (!o) continue;
if (setOrCleared(o.foreground) && attr.fg) {
// No foreground means the default text colour, not invisible text.
const fg = o.foreground === CLEAR_COLOR && attr.id !== "text" ? "var(--fg-editor)" : o.foreground!;
const cleared = attr.fgOverlay ? "inherit" : attr.id === "text" ? CLEAR_COLOR : "var(--fg-editor)";
const fg = o.foreground === CLEAR_COLOR ? cleared : o.foreground!;
out.push([attr.fg, fg]);
// Terminal prefers `--terminal-ansi-*`; keep it in sync with console `--ansi-*`.
if (attr.fg.startsWith("--ansi-")) out.push([`--terminal-ansi-${attr.fg.slice("--ansi-".length)}`, fg]);
+27
View File
@@ -48,6 +48,33 @@ describe(".icls schemes", () => {
expect(parseIcls(xml).scheme.attributes.selectionForeground).toEqual({ foreground: "#ffffff" });
});
it("round trips both caret identifier attributes with their foregrounds (#4109)", () => {
const { scheme } = parseIcls(`<scheme name="Caret" parent_scheme="Darcula"><attributes>
<option name="WRITE_SEARCH_RESULT_ATTRIBUTES"><value><option name="BACKGROUND" value="111111"/></value></option>
<option name="IDENTIFIER_UNDER_CARET_ATTRIBUTES"><value>
<option name="FOREGROUND" value="aa0000"/><option name="BACKGROUND" value="220000"/>
</value></option>
<option name="WRITE_IDENTIFIER_UNDER_CARET_ATTRIBUTES"><value>
<option name="FOREGROUND" value="00aa00"/><option name="BACKGROUND" value="002200"/>
</value></option>
</attributes></scheme>`);
expect(scheme.attributes.identifierUnderCaret).toEqual({ foreground: "#aa0000", background: "#220000" });
expect(scheme.attributes.identifierUnderCaretWrite).toEqual({ foreground: "#00aa00", background: "#002200" });
const { id, customs } = importScheme({}, scheme);
const xml = exportIcls(id, customs);
expect(xml).toContain('name="WRITE_IDENTIFIER_UNDER_CARET_ATTRIBUTES"');
expect(parseIcls(xml).scheme.attributes.identifierUnderCaretWrite).toEqual(
scheme.attributes.identifierUnderCaretWrite,
);
});
it("still reads the write highlight from WRITE_SEARCH_RESULT_ATTRIBUTES alone", () => {
const { scheme } = parseIcls(`<scheme name="Old"><attributes>
<option name="WRITE_SEARCH_RESULT_ATTRIBUTES"><value><option name="BACKGROUND" value="111111"/></value></option>
</attributes></scheme>`);
expect(scheme.attributes.identifierUnderCaretWrite).toEqual({ background: "#111111" });
});
it("resolves explicit attribute inheritance independent of XML order and stops cycles", () => {
const { scheme } = parseIcls(`<scheme name="Inherited"><attributes>
<option name="PHP_PARAMETER" baseAttributes="PHP_VAR"/>
+1
View File
@@ -49,6 +49,7 @@ const ATTRIBUTE_NAMES: Record<string, string> = {
TODO_DEFAULT_ATTRIBUTES: "todo",
SEARCH_RESULT_ATTRIBUTES: "searchResult",
TEXT_SEARCH_RESULT_ATTRIBUTES: "searchResultCurrent",
WRITE_IDENTIFIER_UNDER_CARET_ATTRIBUTES: "identifierUnderCaretWrite",
WRITE_SEARCH_RESULT_ATTRIBUTES: "identifierUnderCaretWrite",
IDENTIFIER_UNDER_CARET_ATTRIBUTES: "identifierUnderCaret",
MATCHED_BRACE_ATTRIBUTES: "matchedBrace",
+4
View File
@@ -215,6 +215,8 @@ html {
--fg-deprecated: #8c8f95;
--bg-identifier-under-caret: #373b39;
--bg-identifier-under-caret-write: #402f33;
--fg-identifier-under-caret: inherit;
--fg-identifier-under-caret-write: inherit;
--fg-inlay: #868a91;
--bg-inlay: #393b40;
--wave-error: #fa6675;
@@ -673,6 +675,8 @@ html {
--fg-deprecated: #6c707e;
--bg-identifier-under-caret: #edebfc;
--bg-identifier-under-caret-write: #fce8f4;
--fg-identifier-under-caret: inherit;
--fg-identifier-under-caret-write: inherit;
--fg-inlay: #73767c;
--bg-inlay: #00000012;
--wave-error: #f50000;