From 7c12c58874644f80dfe8f276b07c1a341bbbac0c Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sat, 21 Nov 2026 07:29:12 +0800 Subject: [PATCH] fix(vcs): align the operations chooser (#4915) fix(vcs): align the operations chooser --- e2e/vcsOperationsLayout.spec.ts | 67 +++++++++++++++++++++++++++++++++ src/features/vcs/actions.tsx | 17 ++++----- src/ui/Menu.module.css | 16 ++++++++ src/ui/Menu.tsx | 20 ++++++---- 4 files changed, 103 insertions(+), 17 deletions(-) create mode 100644 e2e/vcsOperationsLayout.spec.ts diff --git a/e2e/vcsOperationsLayout.spec.ts b/e2e/vcsOperationsLayout.spec.ts new file mode 100644 index 0000000000..9ebe0245f2 --- /dev/null +++ b/e2e/vcsOperationsLayout.spec.ts @@ -0,0 +1,67 @@ +import { expect, openFromTree, test } from "./fixtures"; + +test("VCS Operations keeps its centered title visible in a short window", async ({ workbench: page }) => { + await page.setViewportSize({ width: 640, height: 320 }); + const editor = await openFromTree(page, "README.md"); + const content = editor.locator(".cm-content"); + await content.focus(); + await page.evaluate(async () => { + const actions = "/src/platform/actions.ts"; + await (await import(/* @vite-ignore */ actions)).executeAction("vcs.operations"); + }); + + const menu = page.getByRole("menu", { name: "VCS Operations", exact: true }); + const popup = menu.locator(".."); + const title = popup.getByText("VCS Operations", { exact: true }); + await expect(title).toHaveCSS("font-size", "13px"); + await expect(title).toHaveCSS("font-weight", "600"); + await expect + .poll(async () => { + const box = (await popup.boundingBox())!; + return Math.max(Math.abs(box.x + box.width / 2 - 320), Math.abs(box.y + box.height / 2 - 160)); + }) + .toBeLessThan(2); + const commit = menu.getByRole("menuitem", { name: /^Commit…/ }); + await expect(commit).toBeFocused(); + await expect(commit.locator('[data-menu-number="1"]')).toBeVisible(); + await page.keyboard.press("End"); + const history = menu.getByRole("menuitem", { name: /^Show Local History/ }); + await expect(history).toBeFocused(); + await expect(history).toBeInViewport({ ratio: 1 }); + await expect.poll(() => popup.evaluate((el) => el.scrollTop)).toBeGreaterThan(0); + expect((await title.boundingBox())!.y).toBeGreaterThanOrEqual((await popup.boundingBox())!.y); + await page.keyboard.press("Escape"); + await expect(menu).toBeHidden(); + await expect(content).toBeFocused(); + + await page.evaluate(async () => { + const actions = "/src/platform/actions.ts"; + await (await import(/* @vite-ignore */ actions)).executeAction("vcs.operations"); + }); + await expect(commit).toBeFocused(); + await page.keyboard.press("1"); + await expect(menu).toBeHidden(); + const commitWindow = page.getByRole("region", { name: "Commit", exact: true }); + await expect(commitWindow).toBeVisible(); + const message = commitWindow.getByRole("textbox", { name: "Commit message" }); + await expect(message).toBeFocused(); + expect(await message.evaluate((el) => (el instanceof HTMLTextAreaElement ? el.value : el.textContent))).toBe(""); +}); + +test("VCS Operations offers repository setup and Local History outside Git", async ({ workbench: page }) => { + const editor = await openFromTree(page, "README.md"); + await editor.locator(".cm-content").focus(); + await page.evaluate(async () => { + const project = "/src/platform/project.ts"; + const { useProject } = await import(/* @vite-ignore */ project); + useProject.setState((s: { project: object }) => ({ project: { ...s.project, isGit: false } })); + const context = "/src/platform/context.ts"; + (await import(/* @vite-ignore */ context)).setContext("vcsAvailable", false); + const actions = "/src/platform/actions.ts"; + await (await import(/* @vite-ignore */ actions)).executeAction("vcs.operations"); + }); + + const menu = page.getByRole("menu", { name: "VCS Operations", exact: true }); + await expect(menu.getByRole("menuitem")).toHaveText([/Create Git Repository…/, /Show Local History/]); + await expect(menu.getByRole("menuitem", { name: /^Create Git Repository…/ })).toBeFocused(); +}); diff --git a/src/features/vcs/actions.tsx b/src/features/vcs/actions.tsx index c524016f63..d599453082 100644 --- a/src/features/vcs/actions.tsx +++ b/src/features/vcs/actions.tsx @@ -211,16 +211,15 @@ const OPERATIONS: MenuItem[] = [ { kind: "action", action: "vcs.localHistory" }, ]; +const OPERATIONS_WITHOUT_VCS: MenuItem[] = [ + { kind: "action", action: "vcs.createRepository" }, + { kind: "separator" }, + { kind: "action", action: "vcs.localHistory" }, +]; + function showOperations() { - openDialog((close) => ( - - )); + const items = getContext().vcsAvailable ? OPERATIONS : OPERATIONS_WITHOUT_VCS; + openDialog((close) => ); } export function registerVcsActions(): () => void { diff --git a/src/ui/Menu.module.css b/src/ui/Menu.module.css index edbb5a7225..cb4e131408 100644 --- a/src/ui/Menu.module.css +++ b/src/ui/Menu.module.css @@ -7,6 +7,22 @@ .popup .menu { max-width: 420px; } +.titledPopup { + scroll-padding-block-start: calc(var(--h-list-row) + var(--space-1)); +} +.menuHeading { + position: sticky; + top: 0; + z-index: 1; + display: flex; + align-items: center; + height: calc(var(--h-list-row) + var(--space-1)); + padding-inline: var(--space-3); + background: var(--bg-popup); + color: var(--fg-strong); + font-size: var(--fs-ui); + font-weight: 600; +} .menu { display: flex; flex-direction: column; diff --git a/src/ui/Menu.tsx b/src/ui/Menu.tsx index f11de43f35..a004c4f10c 100644 --- a/src/ui/Menu.tsx +++ b/src/ui/Menu.tsx @@ -338,12 +338,12 @@ export function MenuList({ default: if (e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey) { if (numbers && /^[1-9]$/.test(e.key)) { - const n = Number(e.key); - for (let i = 0; i < resolved.length; i++) - if (numbersOf[i] === n) { - activate(i); - break; - } + const index = numbersOf.indexOf(Number(e.key)); + if (index >= 0) { + e.preventDefault(); + e.stopPropagation(); + activate(index); + } return; } const ch = e.key.toLowerCase(); @@ -475,6 +475,7 @@ export interface MenuProps { onClose: () => void; anchor: PopupAnchor; items: MenuItem[]; + title?: string; iconColumn?: boolean; placement?: Placement; "aria-label"?: string; @@ -488,11 +489,13 @@ export function Menu({ onClose, anchor, items, + title, placement = "bottom-start", iconColumn, numbers, ...aria }: MenuProps) { + const heading = title ? tx(title) : undefined; return ( + {heading &&
{heading}
}
);