From b88aa70aff22b24d41e10e1581552e50ef7af83d Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Mon, 23 Nov 2026 00:46:20 +0800 Subject: [PATCH] fix(run): keep configuration names distinct in gutter menus --- e2e/runGutterMenuLayout.spec.ts | 63 ++++++++++++++++++++++++ src/features/run/contextRun.ts | 1 + src/features/run/launchSettingsGutter.ts | 2 + src/features/run/npmGutter.ts | 2 + src/features/run/runGutter.ts | 9 +++- src/ui/Menu.module.css | 14 ++++++ src/ui/Menu.tsx | 17 ++++++- 7 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 e2e/runGutterMenuLayout.spec.ts diff --git a/e2e/runGutterMenuLayout.spec.ts b/e2e/runGutterMenuLayout.spec.ts new file mode 100644 index 0000000000..3728f3c0de --- /dev/null +++ b/e2e/runGutterMenuLayout.spec.ts @@ -0,0 +1,63 @@ +import { expect, ipcCalls, stubDesktop, test } from "./fixtures"; + +const prefix = "reconcile-regional-inventory-and-rebuild-order-settlement-cache-for-warehouse-"; +const east = prefix + "east-stage"; +const west = prefix + "west-stage"; +const content = JSON.stringify( + { name: "warehouse-tools", scripts: { [east]: "node east.js", [west]: "node west.js", build: "node build.js" } }, + null, + 2, +); + +test("the npm gutter keeps distinct ends of long names and runs the selected script", async ({ workbench: page }) => { + await page.setViewportSize({ width: 440, height: 520 }); + await stubDesktop(page); + await page.evaluate(async (text) => { + const backendPath = "/src/editor/core/backend.ts"; + const servicePath = "/src/workbench/contributions.ts"; + const { docBackend } = await import(/* @vite-ignore */ backendPath); + const { editorService } = await import(/* @vite-ignore */ servicePath); + const path = "/dev/acme-api/package.json"; + docBackend().files.set(path, text); + const handlers = window.__ipc.handlers; + handlers.fs_probe = () => ({ size: text.length, binary: false, tooLarge: false }); + handlers.fs_read_text = ({ path }) => docBackend().files.get(String(path)) ?? ""; + handlers.fs_read_dir = () => []; + handlers.run_configs = () => []; + handlers.run_start = ({ config }) => ({ + id: 7, + configId: (config as { id: string }).id, + name: (config as { name: string }).name, + pid: 4242, + running: true, + pty: false, + }); + await editorService().openFile(path); + }, content); + const editor = page.locator(".cm-editor"); + const menu = page.getByRole("menu", { name: "Context menu" }); + for (const name of [east, west]) { + await editor.getByTitle("Run '" + name + "'", { exact: true }).click(); + const label = "Run 'npm run " + name + "'"; + const run = menu.getByRole("menuitem", { name: label, exact: true }); + const end = run.getByText(label.slice(-12), { exact: true }); + await expect(end).toBeVisible(); + await expect(end.locator("..")).toHaveAttribute("title", label); + expect(await end.evaluate((node) => node.clientWidth >= node.scrollWidth)).toBe(true); + const start = end.locator("..").locator(":scope > span").first(); + expect(await start.evaluate((node) => node.clientWidth < node.scrollWidth)).toBe(true); + await expect(start).toHaveCSS("text-overflow", "ellipsis"); + const titleUnderPointer = await start.evaluate((node) => { + const { x, y, width, height } = node.getBoundingClientRect(); + return document.elementFromPoint(x + width / 2, y + height / 2)?.getAttribute("title"); + }); + expect(titleUnderPointer).toBe(label); + await expect(run).toBeFocused(); + if (name === east) await run.press("Escape"); + else await run.press("Enter"); + await expect(menu).toBeHidden(); + } + await expect + .poll(async () => ipcCalls(page, "run_start")) + .toMatchObject([{ config: { args: ["run", west], kind: "npm" } }]); +}); diff --git a/src/features/run/contextRun.ts b/src/features/run/contextRun.ts index e412659caa..879b0ee29d 100644 --- a/src/features/run/contextRun.ts +++ b/src/features/run/contextRun.ts @@ -262,6 +262,7 @@ export function choiceItems(choices: readonly Produced[], debug: boolean): MenuI { kind: "header", label: debug ? "Choose configuration to debug" : "Choose configuration to run" }, ...choices.map((p): MenuItem => ({ label: debug ? tx`Debug '${p.name}'` : tx`Run '${p.name}'`, + preserveLabelEnd: true, verbatim: true, icon: debug ? "debug" : "run", shortcut: p.detail, diff --git a/src/features/run/launchSettingsGutter.ts b/src/features/run/launchSettingsGutter.ts index aaff002dba..b936e4a5a8 100644 --- a/src/features/run/launchSettingsGutter.ts +++ b/src/features/run/launchSettingsGutter.ts @@ -82,6 +82,7 @@ async function profileMenu(entry: ScriptEntry, path: string): Promise @@ -91,6 +92,7 @@ async function profileMenu(entry: ScriptEntry, path: string): Promise void executeAction("run.debugConfig", config), diff --git a/src/features/run/npmGutter.ts b/src/features/run/npmGutter.ts index 3cf66aef4e..418b7efe1f 100644 --- a/src/features/run/npmGutter.ts +++ b/src/features/run/npmGutter.ts @@ -283,6 +283,7 @@ export async function scriptMenuItems(entry: ScriptEntry, path: string, content: return [ { label: tx`Run '${label}'`, + preserveLabelEnd: true, icon: "run", shortcut: shortcutLabel("run.runContext"), run: () => @@ -292,6 +293,7 @@ export async function scriptMenuItems(entry: ScriptEntry, path: string, content: }, { label: tx`Debug '${label}'`, + preserveLabelEnd: true, icon: "debug", shortcut: shortcutLabel("run.debugContext"), run: () => void executeAction("run.debugConfig", config), diff --git a/src/features/run/runGutter.ts b/src/features/run/runGutter.ts index 4414ee1d7b..9d6d9a8e44 100644 --- a/src/features/run/runGutter.ts +++ b/src/features/run/runGutter.ts @@ -109,11 +109,18 @@ export function targetMenuItems(target: RunTarget, path: string, content: string : { run: () => void launch(target, path, debug, content) }; const debuggable = !p || canDebugProduced(p); return [ - { label: tx`Run '${name}'`, icon: "run", shortcut: shortcutLabel("run.runContext"), ...pick(false) } as MenuItem, + { + label: tx`Run '${name}'`, + preserveLabelEnd: true, + icon: "run", + shortcut: shortcutLabel("run.runContext"), + ...pick(false), + } as MenuItem, ...(debuggable ? [ { label: tx`Debug '${name}'`, + preserveLabelEnd: true, icon: "debug", shortcut: shortcutLabel("run.debugContext"), ...pick(true), diff --git a/src/ui/Menu.module.css b/src/ui/Menu.module.css index 544465bcd9..aac3277576 100644 --- a/src/ui/Menu.module.css +++ b/src/ui/Menu.module.css @@ -79,6 +79,20 @@ overflow: hidden; text-overflow: ellipsis; } +.splitLabel { + display: flex; +} +.labelStart, +.labelEnd { + min-width: 0; + overflow: hidden; + pointer-events: none; + text-overflow: ellipsis; +} +.labelEnd { + flex: none; + max-width: 50%; +} .shortcut { min-width: 0; max-width: 50%; diff --git a/src/ui/Menu.tsx b/src/ui/Menu.tsx index a2c2b80bd1..758fab64df 100644 --- a/src/ui/Menu.tsx +++ b/src/ui/Menu.tsx @@ -43,6 +43,8 @@ export type MenuItem = label: string; /** User text (e.g. a past query): shown as is, never looked up in the catalog. */ verbatim?: boolean; + /** Keep the end of a long label visible when the menu has to truncate it. */ + preserveLabelEnd?: boolean; icon?: IconName | (string & {}); shortcut?: string; disabled?: boolean; @@ -67,6 +69,7 @@ interface Resolved { kind: "item" | "separator" | "header" | "title"; key: string; label: string; + preserveLabelEnd?: boolean; icon?: string; shortcut?: string; disabled?: boolean; @@ -387,6 +390,8 @@ export function MenuList({ ); const hasSub = !!r.submenu; + const characters = r.preserveLabelEnd ? Array.from(r.label) : []; + const split = characters.length > 24 ? characters.length - 12 : 0; return (