diff --git a/packages/theme/src/tui/syntax.ts b/packages/theme/src/tui/syntax.ts index fcca72989b4..12c31e6ab23 100644 --- a/packages/theme/src/tui/syntax.ts +++ b/packages/theme/src/tui/syntax.ts @@ -13,11 +13,15 @@ export function generateSyntax(theme: ResolvedThemeTokens, owner: NativeResource rule(["extmark.file"], feedback.warning.base, { bold: true }), rule(["extmark.agent"], theme.categorical[0][step], { bold: true }), rule(["extmark.skill"], (theme.categorical[1] ?? theme.categorical[0])[step], { bold: true }), - // V1 migration preserves its selected/inverse foreground in this action state. - rule(["extmark.paste"], theme.text.action.primary.focused, { - background: feedback.warning.base, - bold: true, - }), + rule( + ["extmark.paste"], + // The page color: dark in dark mode, light in light mode. A transparent page (the system theme) falls back to the selected-row text. + theme.background.base.a === 1 ? theme.background.base : theme.text.action.primary.focused, + { + background: feedback.warning.base, + bold: true, + }, + ), rule(["comment", "comment.documentation"], syntax.comment, { italic: true }), rule(["string", "symbol", "character.special", "character"], syntax.string), rule(["number", "boolean", "constant", "float"], syntax.number), diff --git a/packages/tui/test/theme/v2/resolve.test.ts b/packages/tui/test/theme/v2/resolve.test.ts index 4a23cd99a39..9a49dd72ed3 100644 --- a/packages/tui/test/theme/v2/resolve.test.ts +++ b/packages/tui/test/theme/v2/resolve.test.ts @@ -10,7 +10,7 @@ import { type ResolvedTheme, type ThemeDefinition, } from "@opencode/theme/tui" -import { getOpenCodeTheme, parseTheme, type ThemeDocumentSource } from "../../../src/theme" +import { getOpenCode2Theme, getOpenCodeTheme, parseTheme, type ThemeDocumentSource } from "../../../src/theme" const opencodeLight = selectTheme(getOpenCodeTheme(), "light") const opencodeDark = selectTheme(getOpenCodeTheme(), "dark") @@ -120,6 +120,24 @@ test("generates syntax with one categorical hue", () => { } }) +test("draws paste chip text dark in dark mode and light in light mode", () => { + for (const mode of ["dark", "light"] as const) { + const theme = resolveThemeDocument(getOpenCode2Theme(), mode) + const owner = new ResourceContext({ objectCapacity: 1, renderCellsMax: 1 }) + const syntax = generateSyntax(theme, owner) + try { + const style = syntax.getStyle("extmark.paste")! + expect(style.bg!.equals(theme.text.feedback.warning.base)).toBeTrue() + const luminance = (color: RGBA) => 0.299 * color.r + 0.587 * color.g + 0.114 * color.b + if (mode === "dark") expect(luminance(style.fg!)).toBeLessThan(luminance(style.bg!)) + else expect(luminance(style.fg!)).toBeGreaterThan(luminance(style.bg!)) + } finally { + syntax.destroy() + owner.destroy() + } + } +}) + test("rejects incomplete themes instead of merging defaults", () => { expect(() => resolveSource({ light: { hue: light.hue } }, "light")).toThrow("Invalid theme") expect(() => resolveSource({ light: { ...light, categorical: undefined } }, "light")).toThrow(