mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-23 08:49:33 -10:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2c07149b9 | ||
|
|
b7037e2116 | ||
|
|
347ddc15e8 |
No files matched your search
@@ -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);
|
||||
});
|
||||
@@ -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<string>("editor.colorScheme", "global");
|
||||
const [overrides, setOverrides] = useSetting<Overrides>("editor.colorOverrides", "global");
|
||||
@@ -1580,7 +1600,7 @@ export function ColorSchemePage({ scopes, landing }: { scopes: readonly string[]
|
||||
[],
|
||||
);
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<div className={landing ? styles.page : styles.schemePage}>
|
||||
<div className={styles.schemeRow}>
|
||||
<Row label="Scheme">
|
||||
<Select value={scheme} options={options} onChange={setScheme} aria-label="Scheme" />
|
||||
@@ -1631,84 +1651,88 @@ export function ColorSchemePage({ scopes, landing }: { scopes: readonly string[]
|
||||
))}
|
||||
</nav>
|
||||
) : (
|
||||
<>
|
||||
<div className={styles.schemeBody} style={baseVars}>
|
||||
<div className={styles.attrTree}>
|
||||
<Tree<Node>
|
||||
aria-label="Color scheme attributes"
|
||||
roots={roots}
|
||||
getKey={(n) => n.key}
|
||||
getLabel={(n) => translate(n.label)}
|
||||
getChildren={(n) => n.children}
|
||||
isExpandable={(n) => !!n.children?.length}
|
||||
expanded={expanded}
|
||||
onExpandedChange={setExpanded}
|
||||
handleRef={treeRef}
|
||||
multiSelect={false}
|
||||
selected={new Set([selected])}
|
||||
onSelectionChange={(_s, lead) => lead?.attr && setSelected(lead.attr.id)}
|
||||
renderNode={(n) => (
|
||||
<span
|
||||
className={`${styles.treeLabel} ${(n.attr ? mine?.[n.attr.id] : modifiedKeys.has(n.key)) ? styles.attrModified : ""}`}
|
||||
>
|
||||
{translate(n.label)}
|
||||
</span>
|
||||
)}
|
||||
speedSearch
|
||||
/>
|
||||
</div>
|
||||
{attr ? (
|
||||
<div className={styles.attrPanel}>
|
||||
<AttributeEditor
|
||||
key={`${id}/${attr.id}`}
|
||||
attr={attr}
|
||||
inherited={inherited}
|
||||
value={mine?.[attr.id]}
|
||||
onChange={(v) => update(attr.id, v)}
|
||||
<SplitGroup orientation="vertical" className={styles.schemeSplit}>
|
||||
<SplitPanel defaultSize="62%" minSize="154px">
|
||||
<div className={styles.schemeBody} style={baseVars}>
|
||||
<div className={styles.attrTree}>
|
||||
<Tree<Node>
|
||||
aria-label="Color scheme attributes"
|
||||
roots={roots}
|
||||
getKey={(n) => n.key}
|
||||
getLabel={(n) => translate(n.label)}
|
||||
getChildren={(n) => n.children}
|
||||
isExpandable={(n) => !!n.children?.length}
|
||||
expanded={expanded}
|
||||
onExpandedChange={setExpanded}
|
||||
handleRef={treeRef}
|
||||
multiSelect={false}
|
||||
selected={new Set([selected])}
|
||||
onSelectionChange={(_s, lead) => lead?.attr && setSelected(lead.attr.id)}
|
||||
renderNode={(n) => (
|
||||
<span
|
||||
className={`${styles.treeLabel} ${(n.attr ? mine?.[n.attr.id] : modifiedKeys.has(n.key)) ? styles.attrModified : ""}`}
|
||||
>
|
||||
{translate(n.label)}
|
||||
</span>
|
||||
)}
|
||||
speedSearch
|
||||
/>
|
||||
</div>
|
||||
<section className={styles.attrPanel} aria-label={tx("Color scheme options")}>
|
||||
{attr && (
|
||||
<AttributeEditor
|
||||
key={`${id}/${attr.id}`}
|
||||
attr={attr}
|
||||
inherited={inherited}
|
||||
value={mine?.[attr.id]}
|
||||
onChange={(v) => update(attr.id, v)}
|
||||
/>
|
||||
)}
|
||||
{children && <div className={styles.schemeExtraOptions}>{children}</div>}
|
||||
</section>
|
||||
</div>
|
||||
</SplitPanel>
|
||||
<SplitHandle aria-label={tx("Resize color scheme preview")} />
|
||||
<SplitPanel defaultSize="38%" minSize="88px">
|
||||
{scopes[0] === "Git" ? (
|
||||
<GitPreview vars={vars} ids={ids} reveal={reveal} />
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
</div>
|
||||
{scopes[0] === "Git" ? (
|
||||
<GitPreview vars={vars} ids={ids} reveal={reveal} />
|
||||
) : (
|
||||
<pre className={styles.schemePreview} style={vars} aria-label={tx("Color scheme preview")}>
|
||||
{sample.code.map((line, i) => (
|
||||
<div key={i} className={`${styles.previewLine} ${i === sample.caret ? styles.previewCaretLine : ""}`}>
|
||||
<span className={styles.previewGutter}>{i + 1}</span>
|
||||
<code>
|
||||
{line.map(([text, attrId], j) => {
|
||||
const attr = attrId !== undefined ? A(attrId) : undefined;
|
||||
const inPage = attr !== undefined && ids.has(attrId!);
|
||||
return (
|
||||
<span
|
||||
key={j}
|
||||
style={tokenStyle(attr)}
|
||||
className={attr ? styles.clickable : undefined}
|
||||
onClick={
|
||||
attr
|
||||
? () => {
|
||||
if (inPage) reveal(attrId!);
|
||||
else {
|
||||
crossPageReveal = attrId!;
|
||||
selectPage(attrPageId(attr));
|
||||
<pre className={styles.schemePreview} style={vars} aria-label={tx("Color scheme preview")}>
|
||||
{sample.code.map((line, i) => (
|
||||
<div key={i} className={`${styles.previewLine} ${i === sample.caret ? styles.previewCaretLine : ""}`}>
|
||||
<span className={styles.previewGutter}>{i + 1}</span>
|
||||
<code>
|
||||
{line.map(([text, attrId], j) => {
|
||||
const attr = attrId !== undefined ? A(attrId) : undefined;
|
||||
const inPage = attr !== undefined && ids.has(attrId!);
|
||||
return (
|
||||
<span
|
||||
key={j}
|
||||
style={tokenStyle(attr)}
|
||||
className={attr ? styles.clickable : undefined}
|
||||
onClick={
|
||||
attr
|
||||
? () => {
|
||||
if (inPage) reveal(attrId!);
|
||||
else {
|
||||
crossPageReveal = attrId!;
|
||||
selectPage(attrPageId(attr));
|
||||
}
|
||||
}
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{text}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</code>
|
||||
</div>
|
||||
))}
|
||||
</pre>
|
||||
)}
|
||||
</>
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{text}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</code>
|
||||
</div>
|
||||
))}
|
||||
</pre>
|
||||
)}
|
||||
</SplitPanel>
|
||||
</SplitGroup>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -223,13 +223,38 @@
|
||||
}
|
||||
.schemeBody {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(180px, 1fr) minmax(220px, 260px);
|
||||
gap: 14px;
|
||||
min-height: 320px;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 280px);
|
||||
gap: var(--space-2);
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
padding-bottom: var(--space-2);
|
||||
}
|
||||
.schemePage {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 340px;
|
||||
min-width: 0;
|
||||
}
|
||||
.schemeSplit {
|
||||
flex: 1;
|
||||
}
|
||||
.schemePage > :not(.schemeSplit) {
|
||||
flex: none;
|
||||
}
|
||||
.schemeExtraOptions {
|
||||
margin-top: var(--space-4);
|
||||
}
|
||||
@container settings-content (max-width: 610px) {
|
||||
.schemeBody {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
grid-template-rows: minmax(72px, 2fr) minmax(0, 3fr);
|
||||
}
|
||||
}
|
||||
.attrTree {
|
||||
max-height: 360px;
|
||||
overflow: auto;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
border-radius: var(--radius-small);
|
||||
box-shadow: inset 0 0 0 1px var(--border-strong);
|
||||
padding: 2px 0;
|
||||
@@ -247,9 +272,9 @@
|
||||
box-shadow: inset 0 0 0 1px var(--border-strong);
|
||||
border-radius: var(--radius-small);
|
||||
padding: 10px;
|
||||
align-self: start;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
max-height: 360px;
|
||||
}
|
||||
.attrEditor {
|
||||
display: flex;
|
||||
@@ -259,6 +284,7 @@
|
||||
.attrRow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2);
|
||||
min-height: 28px;
|
||||
}
|
||||
@@ -274,7 +300,7 @@
|
||||
}
|
||||
.swatchInput {
|
||||
flex: 1 1 90px;
|
||||
min-width: 90px;
|
||||
min-width: min(90px, 100%);
|
||||
}
|
||||
.colorBox {
|
||||
position: relative;
|
||||
@@ -298,7 +324,9 @@
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.schemePreview {
|
||||
margin: 14px 0 0;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
margin: var(--space-2) 0 0;
|
||||
padding: 8px 0;
|
||||
border-radius: var(--radius-small);
|
||||
box-shadow: inset 0 0 0 1px var(--border-strong);
|
||||
@@ -309,7 +337,6 @@
|
||||
font-size: var(--fs-code);
|
||||
line-height: var(--lh-code);
|
||||
overflow: auto;
|
||||
max-height: 260px;
|
||||
}
|
||||
.previewLine {
|
||||
display: flex;
|
||||
@@ -338,12 +365,13 @@
|
||||
/* Git preview mirrors the two real surfaces: the editor inline blame widget and
|
||||
the project tree root branch suffix. Only the Git page uses these. */
|
||||
.gitPreview {
|
||||
margin: 14px 0 0;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
margin: var(--space-2) 0 0;
|
||||
border-radius: var(--radius-small);
|
||||
box-shadow: inset 0 0 0 1px var(--border-strong);
|
||||
background: var(--bg-editor, var(--bg-island));
|
||||
overflow: auto;
|
||||
max-height: 260px;
|
||||
}
|
||||
.gitSection {
|
||||
padding: 8px 0;
|
||||
|
||||
@@ -2,24 +2,34 @@ import { ATTRIBUTES, SCHEMES } from "@/platform/colorScheme";
|
||||
import { lazyPage } from "../lazyPage";
|
||||
import type { PageSpec } from "../spec";
|
||||
import { LANGUAGES, SCHEME_SUBPAGES, languagePageId } from "./colorSchemeMeta";
|
||||
import { editorPage } from "./kit";
|
||||
import { editorPage, EditorSections, sectionLabels, type EditorSection } from "./kit";
|
||||
|
||||
const ALL_COLOR_SCHEME_PAGE_IDS = ["editor.colorScheme", ...SCHEME_SUBPAGES.map((p) => p.id)];
|
||||
const LazyColorSchemePage = lazyPage(ALL_COLOR_SCHEME_PAGE_IDS, () =>
|
||||
import("./ColorSchemeBody").then((m) => m.ColorSchemePage),
|
||||
);
|
||||
|
||||
/** The scope chooser, import/export buttons and preview are identical on every sub-page. */
|
||||
function colorSchemeSection(scopes: readonly string[]) {
|
||||
function colorSchemePage(
|
||||
spec: Pick<PageSpec, "id" | "title" | "order" | "keywords">,
|
||||
scope: string,
|
||||
extraSections: EditorSection[] = [],
|
||||
): PageSpec {
|
||||
const scopes = [scope];
|
||||
const labels = [
|
||||
"Scheme",
|
||||
...ATTRIBUTES.filter((a) => a.path[0] === scope).map((a) => a.name),
|
||||
...sectionLabels(extraSections),
|
||||
];
|
||||
return {
|
||||
items: [
|
||||
{
|
||||
t: "custom" as const,
|
||||
label: "Scheme",
|
||||
keywords: ATTRIBUTES.filter((a) => scopes.includes(a.path[0]!)).map((a) => a.name),
|
||||
component: () => <LazyColorSchemePage scopes={scopes} />,
|
||||
},
|
||||
],
|
||||
...spec,
|
||||
group: "Editor",
|
||||
projectScope: false,
|
||||
dynamicLabels: () => labels,
|
||||
component: () => (
|
||||
<LazyColorSchemePage scopes={scopes}>
|
||||
{extraSections.length > 0 && <EditorSections sections={extraSections} />}
|
||||
</LazyColorSchemePage>
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -55,22 +65,23 @@ const COLOR_SCHEME_PAGE = editorPage({
|
||||
/** JetBrains layout: scopes and languages live in the settings tree under Color Scheme, one page each. */
|
||||
export const COLOR_SCHEME_PAGES: PageSpec[] = [
|
||||
COLOR_SCHEME_PAGE,
|
||||
editorPage({
|
||||
id: "editor.colorScheme.general",
|
||||
title: "General",
|
||||
order: 1,
|
||||
projectScope: false,
|
||||
keywords: ATTRIBUTES.filter((a) => a.path[0] === "General").map((a) => a.name),
|
||||
sections: [colorSchemeSection(["General"])],
|
||||
}),
|
||||
editorPage({
|
||||
id: "editor.colorScheme.language-defaults",
|
||||
title: "Language Defaults",
|
||||
order: 2,
|
||||
projectScope: false,
|
||||
keywords: ["semantic highlighting", "rainbow"],
|
||||
sections: [
|
||||
colorSchemeSection(["Language Defaults"]),
|
||||
colorSchemePage(
|
||||
{
|
||||
id: "editor.colorScheme.general",
|
||||
title: "General",
|
||||
order: 1,
|
||||
},
|
||||
"General",
|
||||
),
|
||||
colorSchemePage(
|
||||
{
|
||||
id: "editor.colorScheme.language-defaults",
|
||||
title: "Language Defaults",
|
||||
order: 2,
|
||||
keywords: ["semantic highlighting", "rainbow"],
|
||||
},
|
||||
"Language Defaults",
|
||||
[
|
||||
{
|
||||
title: "Language Defaults",
|
||||
items: [
|
||||
@@ -101,39 +112,42 @@ export const COLOR_SCHEME_PAGES: PageSpec[] = [
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
editorPage({
|
||||
id: "editor.colorScheme.debugger",
|
||||
title: "Debugger",
|
||||
order: 3,
|
||||
projectScope: false,
|
||||
keywords: ["breakpoint", "inline values"],
|
||||
sections: [colorSchemeSection(["Debugger"])],
|
||||
}),
|
||||
editorPage({
|
||||
id: "editor.colorScheme.console-colors",
|
||||
title: "Console Colors",
|
||||
order: 4,
|
||||
projectScope: false,
|
||||
keywords: ["terminal", "ansi", "console", "background"],
|
||||
sections: [colorSchemeSection(["Console Colors"])],
|
||||
}),
|
||||
editorPage({
|
||||
id: "editor.colorScheme.git",
|
||||
title: "Git",
|
||||
order: 5,
|
||||
projectScope: false,
|
||||
keywords: ["git", "blame", "branch", "inline blame", "project view", "decoration"],
|
||||
sections: [colorSchemeSection(["Git"])],
|
||||
}),
|
||||
),
|
||||
colorSchemePage(
|
||||
{
|
||||
id: "editor.colorScheme.debugger",
|
||||
title: "Debugger",
|
||||
order: 3,
|
||||
keywords: ["breakpoint", "inline values"],
|
||||
},
|
||||
"Debugger",
|
||||
),
|
||||
colorSchemePage(
|
||||
{
|
||||
id: "editor.colorScheme.console-colors",
|
||||
title: "Console Colors",
|
||||
order: 4,
|
||||
keywords: ["terminal", "ansi", "console", "background"],
|
||||
},
|
||||
"Console Colors",
|
||||
),
|
||||
colorSchemePage(
|
||||
{
|
||||
id: "editor.colorScheme.git",
|
||||
title: "Git",
|
||||
order: 5,
|
||||
keywords: ["git", "blame", "branch", "inline blame", "project view", "decoration"],
|
||||
},
|
||||
"Git",
|
||||
),
|
||||
...LANGUAGES.map((language, i) =>
|
||||
editorPage({
|
||||
id: languagePageId(language),
|
||||
title: language,
|
||||
order: 6 + i,
|
||||
projectScope: false,
|
||||
keywords: ATTRIBUTES.filter((a) => a.path[0] === language).map((a) => a.name),
|
||||
sections: [colorSchemeSection([language])],
|
||||
}),
|
||||
colorSchemePage(
|
||||
{
|
||||
id: languagePageId(language),
|
||||
title: language,
|
||||
order: 6 + i,
|
||||
},
|
||||
language,
|
||||
),
|
||||
),
|
||||
];
|
||||
@@ -3,6 +3,8 @@
|
||||
"Resize inspection panes": "Resize inspection panes",
|
||||
"Resize branch comparison panes": "Resize branch comparison panes",
|
||||
"Resize inspection description": "Resize inspection description",
|
||||
"Color scheme options": "Color scheme options",
|
||||
"Resize color scheme preview": "Resize color scheme preview",
|
||||
"Font options": "Font options",
|
||||
"Resize font preview": "Resize font preview",
|
||||
"Table actions": "Table actions",
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
"Resize inspection panes": "调整检查窗格大小",
|
||||
"Resize branch comparison panes": "调整分支比较窗格大小",
|
||||
"Resize inspection description": "调整检查说明窗格大小",
|
||||
"Color scheme options": "配色方案选项",
|
||||
"Resize color scheme preview": "调整配色方案预览大小",
|
||||
"Font options": "字体选项",
|
||||
"Resize font preview": "调整字体预览大小",
|
||||
"Table actions": "表数据操作",
|
||||
|
||||
Reference in new issue
Block a user