diff --git a/apps/desktop/src/lib/__tests__/editorThemes.spec.ts b/apps/desktop/src/lib/__tests__/editorThemes.spec.ts index dc8c82ad7d..3366963833 100644 --- a/apps/desktop/src/lib/__tests__/editorThemes.spec.ts +++ b/apps/desktop/src/lib/__tests__/editorThemes.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { buildEditorFontThemeRules, buildSqlCompletionThemeRules, editorDiagnosticColors, editorThemeAppearanceFor, resolveCustomThemeBackgrounds, resolveEditorTheme, SQL_BUILTIN_HIGHLIGHT_TAG } from "@/lib/editor/editorThemes"; +import { buildEditorFontThemeRules, buildSqlCompletionThemeRules, editorDiagnosticColors, editorThemeAppearanceFor, IDE_EDITOR_THEMES, resolveCustomThemeBackgrounds, resolveEditorTheme, SQL_BUILTIN_HIGHLIGHT_TAG } from "@/lib/editor/editorThemes"; import { DEFAULT_APP_CUSTOM_UI_COLORS, wcagContrastRatio, type AppThemePalette } from "@/lib/app/appTheme"; import type { EditorTheme } from "@/stores/settingsStore"; import { createDbxCodeMirrorSqlDialect } from "@/lib/editor/codemirrorSqlDialect"; @@ -150,6 +150,27 @@ describe("custom editor theme backgrounds", () => { }); }); +describe("Cursor editor theme selection", () => { + // The Cursor palettes track Cursor/VS Code's own `editor.selectionBackground` + // (#264F78 dark, #ADD6FF light). They previously used translucent neutrals + // (#40404099 over #181818, #1414141e over #fcfcfc) which composited to #303030 / + // #e1e1e1 — visually almost identical to the editor background, so a mouse + // selection was hard to spot. + it("paints the selection opaque and clearly visible on the editor background", () => { + const dark = IDE_EDITOR_THEMES.cursorDark; + const light = IDE_EDITOR_THEMES.cursorLight; + + expect(dark.selection).toBe("#264f78"); + expect(light.selection).toBe("#add6ff"); + // Opaque, so the highlight cannot wash out against the editor background. + expect(dark.selection).toMatch(/^#[0-9a-f]{6}$/); + expect(light.selection).toMatch(/^#[0-9a-f]{6}$/); + // Selected text must stay legible inside the highlight. + expect(wcagContrastRatio(dark.foreground, dark.selection), `cursor-dark text on selection`).toBeGreaterThanOrEqual(3.0); + expect(wcagContrastRatio(light.foreground, light.selection), `cursor-light text on selection`).toBeGreaterThanOrEqual(3.0); + }); +}); + describe("SQL completion theme", () => { it("uses the configurable medium radius for the popup container", () => { const rules = buildSqlCompletionThemeRules(); diff --git a/apps/desktop/src/lib/editor/editorThemes.ts b/apps/desktop/src/lib/editor/editorThemes.ts index 98a47fb987..cb8693af39 100644 --- a/apps/desktop/src/lib/editor/editorThemes.ts +++ b/apps/desktop/src/lib/editor/editorThemes.ts @@ -228,7 +228,7 @@ function createCustomTheme(EditorView: typeof import("@codemirror/view").EditorV return [theme, syntaxHighlighting(highlightStyle)]; } -type IdeEditorThemeColors = { +export type IdeEditorThemeColors = { dark: boolean; background: string; foreground: string; @@ -263,7 +263,7 @@ type IdeEditorThemeColors = { numberBold?: boolean; }; -const IDE_EDITOR_THEMES = { +export const IDE_EDITOR_THEMES = { ideaLight: { dark: false, background: "#ffffff", @@ -398,7 +398,10 @@ const IDE_EDITOR_THEMES = { dark: false, background: "#fcfcfc", foreground: "#141414eb", - selection: "#1414141e", + // Cursor/VS Code light `editor.selectionBackground`. The previous translucent + // neutral (#1414141e) composited to a near-background #e1e1e1 on the #fcfcfc + // canvas, so a mouse selection was barely visible. + selection: "#add6ff", selectionMatch: "#14141411", cursor: "#141414eb", gutterBackground: "#fcfcfc", @@ -429,7 +432,10 @@ const IDE_EDITOR_THEMES = { dark: true, background: "#181818", foreground: "#e4e4e4eb", - selection: "#40404099", + // Cursor/VS Code dark `editor.selectionBackground`. The previous translucent + // neutral (#40404099) composited to #303030 on the #181818 canvas — visually + // almost indistinguishable from the editor background. + selection: "#264f78", selectionMatch: "#404040cc", cursor: "#e4e4e4eb", gutterBackground: "#181818",