Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 4970aa8836 fix(vcs): align the New Worktree dialog 2026-11-23 13:16:33 +08:00
l0ng-ai f1c556e2ec fix(editor): align the Find Usages source preview (#5305)
- Start with equal space for the results tree and source preview. Each orientation restores its saved split and starts at 50/50 when it has no saved split.
- Follow the editor's line height and size the preview gutter for the document's longest line number. Keep the selected line visible when the panel height or line metrics change.
2026-11-23 12:42:18 +08:00
8 змінених файлів з 389 додано та 122 видалено

No files matched your search

+83
Переглянути файл
@@ -0,0 +1,83 @@
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
test("New Worktree keeps form fields aligned and creates the selected worktree in a short window", async ({
workbench: page,
}) => {
await page.setViewportSize({ width: 1120, height: 740 });
await stubDesktop(page);
await page.evaluate(async () => {
const root = "/dev/acme-api";
const service = `${root}/service`;
window.__ipc.handlers.vcs_branches = () => [{ name: "main", current: true, remote: false }];
window.__ipc.handlers.vcs_tags = () => [];
window.__ipc.handlers.vcs_worktrees = ({ repo }) => [{ path: repo, branch: "main", main: true, submodule: false }];
window.__ipc.handlers.vcs_worktree_include = () => ({ exists: true });
window.__ipc.handlers.vcs_add_worktree = () => ({ copyWarning: null, setupWarning: null });
const store = "/src/features/vcs/store.ts";
const { useVcs } = await import(/* @vite-ignore */ store);
useVcs.setState({ root, roots: [root, service], repo: root, available: true });
const context = "/src/platform/context.ts";
const { setContext } = await import(/* @vite-ignore */ context);
setContext("vcsAvailable", true);
const actions = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ actions);
await executeAction("vcs.newWorktree");
});
const dialog = page.getByRole("dialog", { name: "New Worktree" });
const name = dialog.getByRole("textbox", { name: "Name:" });
const branch = dialog.getByRole("textbox", { name: "New branch name" });
const location = dialog.getByRole("textbox", { name: "Location:" });
const repository = dialog.getByRole("button", { name: "Repository", exact: true });
const checkout = dialog.getByRole("button", { name: "Check out", exact: true });
const setup = dialog.getByRole("checkbox", { name: "Run setup script" });
const script = dialog.getByRole("textbox", { name: "Setup script:" });
await expect(name).toHaveValue("acme-api-main-wt");
await branch.fill("review/ledger-batch");
await name.fill("ledger-review");
await location.fill("/dev/reviews");
await setup.check();
await script.fill("/dev/setup.sh");
const preview = dialog.getByText("Worktree location: /dev/reviews/ledger-review", { exact: true });
await expect(preview).toBeVisible();
for (const size of [
{ width: 1120, height: 740 },
{ width: 440, height: 520 },
]) {
await page.setViewportSize(size);
const column = (await name.boundingBox())!.x;
for (const [label, field] of [
["Name:", name],
["Location:", location],
["Repository:", repository],
["Check out:", checkout],
["Create a new branch", branch],
["Setup script:", script],
] as const) {
const caption = dialog.getByText(label, { exact: true });
await expect(caption).toBeVisible();
const captionBox = (await caption.boundingBox())!;
const fieldBox = (await field.boundingBox())!;
expect(fieldBox.x, label).toBeCloseTo(column, 0);
expect(captionBox.x + captionBox.width, label).toBeLessThanOrEqual(fieldBox.x);
expect(captionBox.y + captionBox.height / 2, label).toBeCloseTo(fieldBox.y + fieldBox.height / 2, 0);
}
expect((await preview.boundingBox())!.x).toBeCloseTo(column, 0);
}
await setup.uncheck();
await expect(script).toHaveCount(0);
await dialog.getByRole("button", { name: "Create", exact: true }).click();
await expect(dialog).toHaveCount(0);
expect(await ipcCalls(page, "vcs_add_worktree")).toEqual([
{
repo: "/dev/acme-api",
path: "/dev/reviews/ledger-review",
commitish: "refs/heads/main",
newBranch: "review/ledger-batch",
copyConfig: true,
setup: null,
},
]);
});
+95
Переглянути файл
@@ -0,0 +1,95 @@
import type { Page } from "@playwright/test";
import { expect, stubDesktop, test } from "./fixtures";
async function setEditorMetrics(page: Page, fontSize: number, lineHeight: number) {
await page.evaluate(
async ({ fontSize, lineHeight }) => {
const projectModule = "/src/platform/project.ts";
const { useProject } = await import(/* @vite-ignore */ projectModule);
const { settings, project } = useProject.getState();
const current = settings ?? project?.settings;
if (!current) throw new Error("Expected project settings");
useProject.setState({ settings: { ...current, editor: { ...current.editor, fontSize, lineHeight } } });
},
{ fontSize, lineHeight },
);
}
async function openResults(page: Page) {
await page.setViewportSize({ width: 1120, height: 720 });
await stubDesktop(page);
await setEditorMetrics(page, 20, 34);
await page.evaluate(async () => {
const lines = Array.from({ length: 1240 }, () => "");
lines[1233] = " record(orderTotal);";
lines[1237] = " return orderTotal;";
window.__ipc.handlers.fs_read_text = () => lines.join("\n");
const actionsModule = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
await executeAction("find.showUsageResults", {
symbol: "orderTotal",
locations: [
{
path: "/dev/acme-api/src/orderTotals.ts",
range: { start: { line: 1233, col: 9 }, end: { line: 1233, col: 19 } },
},
{
path: "/dev/acme-api/src/orderTotals.ts",
range: { start: { line: 1237, col: 9 }, end: { line: 1237, col: 19 } },
},
],
});
});
const view = page.getByRole("region", { name: "Find Usages", exact: true });
await view.getByRole("treeitem").filter({ hasText: "1234" }).click();
const preview = view.getByRole("region", { name: "Preview", exact: true });
await expect(preview.locator("mark")).toHaveCount(2);
return { view, preview };
}
test("Find Usages preview follows editor line height and fits long line numbers", async ({ workbench: page }) => {
const { preview } = await openResults(page);
await expect(preview).toHaveCSS("font-size", "20px");
await expect(preview).toHaveCSS("line-height", "34px");
const number = preview.getByText("1234", { exact: true });
const gutter = await number.evaluate((element) => {
const range = document.createRange();
range.selectNodeContents(element);
const text = range.getBoundingClientRect();
const box = element.getBoundingClientRect();
return { textInset: text.left - box.left, width: box.width };
});
expect(gutter.textInset).toBeGreaterThanOrEqual(1);
await expect(number).toBeInViewport({ ratio: 0.98 });
expect((await preview.getByText("999", { exact: true }).boundingBox())!.width).toBeCloseTo(gutter.width, 0);
await page.setViewportSize({ width: 560, height: 720 });
await setEditorMetrics(page, 20, 39);
await expect(preview).toHaveCSS("line-height", "39px");
await expect(number).toBeInViewport({ ratio: 0.98 });
});
test("Find Usages starts with equal panes and keeps a separate saved size for each orientation", async ({
workbench: page,
}) => {
const { view } = await openResults(page);
const divider = view.locator('[id="usages-preview-split"]').getByRole("separator");
await expect(divider).toHaveAttribute("aria-valuenow", "50");
await divider.press("ArrowRight");
await expect(divider).not.toHaveAttribute("aria-valuenow", "50");
const horizontal = (await divider.getAttribute("aria-valuenow"))!;
await page.setViewportSize({ width: 560, height: 720 });
await expect(divider).toHaveAttribute("aria-orientation", "horizontal");
await expect(divider).toHaveAttribute("aria-valuenow", "50");
await divider.press("ArrowDown");
await expect(divider).not.toHaveAttribute("aria-valuenow", "50");
const vertical = (await divider.getAttribute("aria-valuenow"))!;
await page.setViewportSize({ width: 1120, height: 720 });
await expect(divider).toHaveAttribute("aria-orientation", "vertical");
await expect(divider).toHaveAttribute("aria-valuenow", horizontal);
await page.setViewportSize({ width: 560, height: 720 });
await expect(divider).toHaveAttribute("aria-valuenow", vertical);
});
+1 -1
Переглянути файл
@@ -159,7 +159,7 @@
flex-direction: column;
font-family: var(--font-mono);
font-size: var(--fs-code);
line-height: 1.45;
line-height: var(--lh-code);
}
.sourcePreview .sourceText[role="region"] {
font: inherit;
+13 -2
Переглянути файл
@@ -406,6 +406,8 @@ export function useUsagesHeaderMenu(): MenuItem[] {
];
}
const DEFAULT_PREVIEW_LAYOUT = { usages: 50, preview: 50 };
function UsagesSplit({ preview, children }: { preview: ReactNode; children: ReactNode }) {
const show = useUsagesOptions((s) => s.preview);
const frame = useRef<HTMLDivElement>(null);
@@ -427,12 +429,13 @@ function UsagesSplit({ preview, children }: { preview: ReactNode; children: Reac
orientation={stacked ? "vertical" : "horizontal"}
id="usages-preview-split"
storageKey={stacked ? "openidea.usages.previewSplit.vertical" : "openidea.usages.previewSplit"}
defaultLayout={DEFAULT_PREVIEW_LAYOUT}
>
<SplitPanel id="usages" minSize={stacked ? "30%" : 160} className={styles.panel}>
{children}
</SplitPanel>
<SplitHandle />
<SplitPanel id="preview" minSize={stacked ? "30%" : 160} defaultSize="45%" className={styles.panel}>
<SplitPanel id="preview" minSize={stacked ? "30%" : 160} className={styles.panel}>
{preview}
</SplitPanel>
</SplitGroup>
@@ -455,13 +458,21 @@ function UsagesPreview({ node }: { node: Node | null }) {
return (group?.usages ?? []).map((u) => ({ line: u.line, ranges: [[u.col, u.endCol] as const] }));
}, [usage, search?.groups]);
return (
<div className={styles.sourcePreview} style={{ fontFamily, fontSize: settings?.fontSize ?? undefined }}>
<div
className={styles.sourcePreview}
style={{
fontFamily,
fontSize: settings?.fontSize ?? undefined,
lineHeight: settings?.lineHeight != null ? `${settings.lineHeight}px` : undefined,
}}
>
<SourcePreview
path={usage?.path ?? null}
line={usage?.line ?? 0}
highlights={highlights}
load={previewText}
colorize={previewColors}
editorLayout
className={styles.sourceText}
/>
</div>
+128 -113
Переглянути файл
@@ -100,6 +100,7 @@ function WorktreeForm({
onRepoChange: (repo: string) => void;
}) {
const [projectRoot] = useState(() => useProject.getState().project?.root);
const [hasRepositories] = useState(() => useVcs.getState().roots.length > 1);
const [data, setData] = useState<RepositoryData>();
const [sourceRef, setSourceRef] = useState(initialSource);
const [createBranch, setCreateBranch] = useState<boolean>();
@@ -367,128 +368,142 @@ function WorktreeForm({
]}
>
<div className={styles.form}>
{!initialSource && (
<RepoPicker
repo={repo}
onChange={(next) => {
if (!submitting.current) onRepoChange(next);
}}
/>
)}
{main?.submodule && (
<div className={styles.worktreeTarget}>
{tx("This worktree has its own checkout, separate from the submodule in the parent repository.")}
</div>
)}
<div className={styles.fieldLabel}>
<T>Check out:</T>
</div>
<Select
aria-label="Check out"
searchable
disabled={formBusy || !data}
value={source?.ref ?? null}
placeholder="Select branch or tag"
options={(data?.sources ?? []).map((ref) => ({
value: ref.ref,
label: ref.name,
icon: ref.kind === "tag" ? "tag" : "branch",
verbatim: true,
}))}
onChange={(ref) => {
setSourceRef(ref);
setCreateBranch(undefined);
setBranch(undefined);
setError(undefined);
}}
/>
<Checkbox label="Create a new branch" disabled={formBusy} checked={createLocal} onChange={setCreateBranch} />
{createLocal && (
<Input
ref={branchInput}
aria-label="New branch name"
mono
disabled={formBusy}
value={branch ?? branchName}
onChange={(e) => setBranch(cleanBranch(e))}
/>
)}
<label className={styles.fieldLabel} htmlFor="worktree-name">
<T>Name:</T>
</label>
<Input
id="worktree-name"
mono
disabled={formBusy}
value={name ?? folderName}
onChange={(e) => setName(e.target.value)}
/>
<label className={styles.fieldLabel} htmlFor="worktree-location">
<T>Location:</T>
</label>
<div className={styles.worktreeLocation}>
<Input
id="worktree-location"
mono
disabled={formBusy}
value={location ?? parent}
onChange={(e) => setLocation(e.target.value)}
/>
<IconButton icon="folder-open" title="Browse" disabled={formBusy} onClick={() => void browse()} />
</div>
{parent && folderName && <div className={styles.worktreeTarget}>{tx`Worktree location: ${target}`}</div>}
<div className={styles.worktreeLocation}>
<Checkbox
label="Copy local files listed in .worktreeinclude"
disabled={formBusy || !include?.exists}
checked={copyLocal}
onChange={setCopyConfig}
/>
{include && (
<Button disabled={formBusy} onClick={() => void editInclude()}>
<T>{include.exists ? "Edit .worktreeinclude…" : "Create .worktreeinclude…"}</T>
</Button>
)}
</div>
{includeError && (
<div className={styles.error} role="alert">
{includeError}
</div>
)}
<Checkbox
label="Run setup script"
disabled={formBusy}
checked={runSetup}
onChange={(enabled) => {
setRunSetup(enabled);
setError(undefined);
}}
/>
{runSetup && (
<>
<label className={styles.fieldLabel} htmlFor="worktree-setup-script">
<T>Setup script:</T>
</label>
<div className={styles.worktreeLocation}>
<Input
id="worktree-setup-script"
mono
disabled={formBusy}
value={setupPath}
onChange={(e) => {
setSetupPath(e.target.value);
setError(undefined);
<div className={styles.worktreeFields}>
{!initialSource && hasRepositories && (
<>
<label className={styles.worktreeLabel} htmlFor="worktree-repository">
<T>Repository:</T>
</label>
<RepoPicker
id="worktree-repository"
repo={repo}
onChange={(next) => {
if (!submitting.current) onRepoChange(next);
}}
/>
<IconButton
icon="folder-open"
title="Choose Setup Script"
disabled={formBusy}
onClick={() => void browseSetupScript()}
</>
)}
<label className={styles.worktreeLabel} htmlFor="worktree-source">
<T>Check out:</T>
</label>
<Select
id="worktree-source"
aria-label="Check out"
searchable
disabled={formBusy || !data}
value={source?.ref ?? null}
placeholder="Select branch or tag"
options={(data?.sources ?? []).map((ref) => ({
value: ref.ref,
label: ref.name,
icon: ref.kind === "tag" ? "tag" : "branch",
verbatim: true,
}))}
onChange={(ref) => {
setSourceRef(ref);
setCreateBranch(undefined);
setBranch(undefined);
setError(undefined);
}}
/>
<Checkbox
className={styles.worktreeLabel}
label="Create a new branch"
disabled={formBusy}
checked={createLocal}
onChange={setCreateBranch}
/>
{createLocal && (
<Input
ref={branchInput}
aria-label="New branch name"
mono
disabled={formBusy}
value={branch ?? branchName}
onChange={(e) => setBranch(cleanBranch(e))}
/>
)}
<label className={styles.worktreeLabel} htmlFor="worktree-name">
<T>Name:</T>
</label>
<Input
id="worktree-name"
disabled={formBusy}
value={name ?? folderName}
onChange={(e) => setName(e.target.value)}
/>
<label className={styles.worktreeLabel} htmlFor="worktree-location">
<T>Location:</T>
</label>
<div className={styles.worktreeLocation}>
<Input
id="worktree-location"
disabled={formBusy}
value={location ?? parent}
onChange={(e) => setLocation(e.target.value)}
/>
<IconButton icon="folder-open" title="Browse" disabled={formBusy} onClick={() => void browse()} />
</div>
{parent && folderName && <div className={styles.worktreeTarget}>{tx`Worktree location: ${target}`}</div>}
<div className={styles.worktreeOptions}>
<div className={styles.worktreeCopyOptions}>
<Checkbox
label="Copy local files listed in .worktreeinclude"
disabled={formBusy || !include?.exists}
checked={copyLocal}
onChange={setCopyConfig}
/>
{include && (
<Button disabled={formBusy} onClick={() => void editInclude()}>
<T>{include.exists ? "Edit .worktreeinclude…" : "Create .worktreeinclude…"}</T>
</Button>
)}
</div>
</>
)}
{includeError && (
<div className={styles.error} role="alert">
{includeError}
</div>
)}
<Checkbox
label="Run setup script"
disabled={formBusy}
checked={runSetup}
onChange={(enabled) => {
setRunSetup(enabled);
setError(undefined);
}}
/>
</div>
{runSetup && (
<>
<label className={styles.worktreeLabel} htmlFor="worktree-setup-script">
<T>Setup script:</T>
</label>
<div className={styles.worktreeLocation}>
<Input
id="worktree-setup-script"
disabled={formBusy}
value={setupPath}
onChange={(e) => {
setSetupPath(e.target.value);
setError(undefined);
}}
/>
<IconButton
icon="folder-open"
title="Choose Setup Script"
disabled={formBusy}
onClick={() => void browseSetupScript()}
/>
</div>
</>
)}
</div>
{busy && (
<div className={styles.worktreeTarget} role="status">
{setupRequest && !skippingSetup ? tx("Creating worktree and running setup…") : tx("Creating worktree…")}
+33
Переглянути файл
@@ -791,6 +791,36 @@
align-items: center;
gap: var(--space-0-5);
}
.worktreeFields {
display: grid;
grid-template-columns: fit-content(44%) minmax(0, 1fr);
align-items: center;
gap: var(--space-2) var(--space-3);
}
.worktreeFields > :not(.worktreeLabel) {
grid-column: 2;
min-width: 0;
}
.worktreeLabel {
grid-column: 1;
min-width: 0;
font-size: var(--fs-ui);
overflow-wrap: anywhere;
}
.worktreeFields > .worktreeOptions {
display: flex;
flex-direction: column;
grid-column: 1 / -1;
gap: var(--space-2);
border-top: 1px solid var(--border);
padding-top: var(--space-2);
}
.worktreeCopyOptions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--space-1) var(--space-2);
}
.worktreeLocation {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
@@ -801,6 +831,9 @@
color: var(--fg-muted);
overflow-wrap: anywhere;
}
.worktreeFields > .worktreeTarget {
font-size: var(--fs-small);
}
.comparisonDialog > [data-dialog-body] {
display: flex;
flex-direction: column;
+2 -2
Переглянути файл
@@ -41,8 +41,8 @@
flex: none;
position: sticky;
left: 0;
width: 48px;
padding-right: 12px;
width: var(--source-preview-gutter-width, 48px);
padding-right: var(--space-3);
text-align: right;
color: var(--fg-gutter);
background-color: var(--bg-app);
+34 -4
Переглянути файл
@@ -9,7 +9,7 @@
* Usages. Files beyond `MAX_PARSE` stay plain rather than colouring the window
* with the wrong block-comment context.
*/
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react";
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from "react";
import clsx from "clsx";
import { T } from "./T";
import { tokenSpans, type SourceToken } from "./tokenSpans";
@@ -46,6 +46,8 @@ export interface SourcePreviewProps {
version?: number;
/** Stable (module-level) syntax colouring; without it lines stay plain. */
colorize?: SourceColorizer;
/** Fit the gutter to the line numbers and keep the selected line visible when the pane resizes. */
editorLayout?: boolean;
className?: string;
}
@@ -56,6 +58,7 @@ export function SourcePreview({
load,
version = 0,
colorize,
editorLayout,
className,
}: SourcePreviewProps) {
const [text, setText] = useState<{ path: string; lines: string[] } | null>(null);
@@ -160,6 +163,7 @@ export function SourcePreview({
lines={current.lines}
tokensByLine={tokensByLine}
highlights={highlights}
editorLayout={editorLayout}
className={className}
/>
);
@@ -176,6 +180,7 @@ function PreviewBody({
lines,
tokensByLine,
highlights,
editorLayout,
className,
}: {
path: string;
@@ -183,6 +188,7 @@ function PreviewBody({
lines: string[];
tokensByLine: Map<number, SourceToken[]> | null;
highlights: readonly SourceHighlight[];
editorLayout?: boolean;
className?: string;
}) {
const scrollRef = useRef<HTMLDivElement>(null);
@@ -192,8 +198,21 @@ function PreviewBody({
useLayoutEffect(() => {
const box = scrollRef.current;
const el = box?.querySelector<HTMLElement>(`[data-line="${line}"]`);
if (box && el) box.scrollTop = el.offsetTop - box.clientHeight / 2 + el.offsetHeight / 2;
}, [line, path, lines]);
if (!box || !el) return;
const center = () => {
box.scrollTop = el.offsetTop - box.clientHeight / 2 + el.offsetHeight / 2;
};
center();
if (!editorLayout || typeof ResizeObserver === "undefined") return;
const observer = new ResizeObserver(() => {
if (el.offsetTop < box.scrollTop || el.offsetTop + el.offsetHeight > box.scrollTop + box.clientHeight) {
center();
}
});
observer.observe(box);
observer.observe(el);
return () => observer.disconnect();
}, [editorLayout, line, path, lines]);
const byLine = new Map(highlights.map((h) => [h.line, h.ranges]));
const start = Math.max(0, line - WINDOW);
@@ -214,7 +233,18 @@ function PreviewBody({
}
return (
<div ref={scrollRef} className={clsx(styles.preview, className)} role="region" aria-label={tx("Preview")}>
<pre className={styles.pre}>{rows}</pre>
<pre
className={styles.pre}
style={
editorLayout
? ({
"--source-preview-gutter-width": `calc(${String(lines.length).length}ch + var(--space-4))`,
} as CSSProperties)
: undefined
}
>
{rows}
</pre>
</div>
);
}