From 1bb4ffe6b2a26247cf69785db01fdb5a11407d72 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Fri, 20 Nov 2026 10:22:05 +0800 Subject: [PATCH] Keep the color scheme preview visible while editing (#4653) The color scheme preview stays visible while editing scheme options. Verified with e2e colorSchemeLayout/editorFontLayout, settings and platform vitest and typecheck; main merged in (locale conflict resolved). --- e2e/colorSchemeLayout.spec.ts | 40 ++++ .../settings/pages/editor/ColorSchemeBody.tsx | 180 ++++++++++-------- .../settings/pages/editor/Editor.module.css | 52 +++-- .../settings/pages/editor/colorScheme.tsx | 134 +++++++------ src/platform/locales/text/en.json | 2 + src/platform/locales/text/zh.json | 2 + 6 files changed, 260 insertions(+), 150 deletions(-) create mode 100644 e2e/colorSchemeLayout.spec.ts diff --git a/e2e/colorSchemeLayout.spec.ts b/e2e/colorSchemeLayout.spec.ts new file mode 100644 index 000000000..4fb8cc160 --- /dev/null +++ b/e2e/colorSchemeLayout.spec.ts @@ -0,0 +1,40 @@ +import { expect, test } from "./fixtures"; + +test("Color Scheme keeps the preview visible while editing an attribute in narrow Settings", async ({ + workbench: page, +}) => { + await page.setViewportSize({ width: 1120, height: 760 }); + await page.keyboard.press("Meta+,"); + const settings = page.getByRole("dialog", { name: "Settings", exact: true }); + const search = settings.getByRole("textbox", { name: "Search settings" }); + await search.fill("Language Defaults"); + await settings.getByRole("treeitem", { name: "Language Defaults", exact: true }).click(); + await search.clear(); + + const divider = settings.getByRole("separator", { name: "Resize color scheme preview", exact: true }); + const tree = settings.getByRole("tree", { name: "Color scheme attributes", exact: true }); + const options = settings.getByRole("region", { name: "Color scheme options", exact: true }); + const preview = settings.getByLabel("Color scheme preview", { exact: true }); + await expect(divider).toHaveAttribute("aria-orientation", "horizontal"); + expect((await tree.boundingBox())!.x).toBeLessThan((await options.boundingBox())!.x); + + await page.setViewportSize({ width: 520, height: 660 }); + await expect.poll(async () => (await tree.boundingBox())!.y).toBeLessThan((await options.boundingBox())!.y); + const previewTop = (await preview.boundingBox())!.y; + const token = preview.getByText("class", { exact: true }).first(); + await token.click(); + await expect(tree.getByRole("treeitem", { name: "Keyword", exact: true, selected: true })).toBeVisible(); + await options.getByRole("textbox", { name: "Foreground hex", exact: true }).fill("#118899"); + await expect(token).toHaveCSS("color", "rgb(17, 136, 153)"); + await expect(preview).toBeInViewport(); + expect((await preview.boundingBox())!.y).toBeCloseTo(previewTop, 0); + await expect + .poll(() => settings.locator("[class*='pageBody']").evaluate((el) => el.scrollWidth - el.clientWidth)) + .toBeLessThanOrEqual(1); + await options.getByRole("checkbox", { name: "Semantic highlighting" }).scrollIntoViewIfNeeded(); + expect((await preview.boundingBox())!.y).toBeCloseTo(previewTop, 0); + + const before = (await divider.boundingBox())!.y; + await divider.press("ArrowUp"); + await expect.poll(async () => (await divider.boundingBox())!.y).toBeLessThan(before - 1); +}); diff --git a/src/features/settings/pages/editor/ColorSchemeBody.tsx b/src/features/settings/pages/editor/ColorSchemeBody.tsx index 46ed4b7fc..bcb21f5f3 100644 --- a/src/features/settings/pages/editor/ColorSchemeBody.tsx +++ b/src/features/settings/pages/editor/ColorSchemeBody.tsx @@ -5,8 +5,20 @@ import { SCHEME_SUBPAGES, languagePageId } from "./colorSchemeMeta"; * italic / effects editor, and a live preview. Edits are staged in * `editor.colorOverrides[scheme][attribute]`; `editor/core` injects them. */ -import { useEffect, useMemo, useRef, useState, type CSSProperties } from "react"; -import { Button, Checkbox, Icon, Input, Tree, type SelectOption, type TreeHandle, T } from "@/ui"; +import { useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from "react"; +import { + Button, + Checkbox, + Icon, + Input, + SplitGroup, + SplitHandle, + SplitPanel, + Tree, + type SelectOption, + type TreeHandle, + T, +} from "@/ui"; import { fontWeightVars, type CustomColorSchemes, type TextAttributesOverride } from "@/platform/editorSettings"; import { ATTRIBUTES, @@ -1368,7 +1380,15 @@ function GitPreview({ ); } -export function ColorSchemePage({ scopes, landing }: { scopes: readonly string[]; landing?: boolean }) { +export function ColorSchemePage({ + scopes, + landing, + children, +}: { + scopes: readonly string[]; + landing?: boolean; + children?: ReactNode; +}) { const translate = useTx(); const [scheme, setScheme] = useSetting("editor.colorScheme", "global"); const [overrides, setOverrides] = useSetting("editor.colorOverrides", "global"); @@ -1580,7 +1600,7 @@ export function ColorSchemePage({ scopes, landing }: { scopes: readonly string[] [], ); return ( -
+