mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-23 08:49:33 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b88aa70aff |
No files matched your search
@@ -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" } }]);
|
||||
});
|
||||
@@ -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,
|
||||
|
||||
@@ -82,6 +82,7 @@ async function profileMenu(entry: ScriptEntry, path: string): Promise<MenuItem[]
|
||||
return [
|
||||
{
|
||||
label: tx`Run '${config.name}'`,
|
||||
preserveLabelEnd: true,
|
||||
icon: "run",
|
||||
shortcut: shortcutLabel("run.runContext"),
|
||||
run: () =>
|
||||
@@ -91,6 +92,7 @@ async function profileMenu(entry: ScriptEntry, path: string): Promise<MenuItem[]
|
||||
},
|
||||
{
|
||||
label: tx`Debug '${config.name}'`,
|
||||
preserveLabelEnd: true,
|
||||
icon: "debug",
|
||||
shortcut: shortcutLabel("run.debugContext"),
|
||||
run: () => void executeAction("run.debugConfig", config),
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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%;
|
||||
|
||||
+15
-2
@@ -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({
|
||||
</div>
|
||||
);
|
||||
const hasSub = !!r.submenu;
|
||||
const characters = r.preserveLabelEnd ? Array.from(r.label) : [];
|
||||
const split = characters.length > 24 ? characters.length - 12 : 0;
|
||||
return (
|
||||
<Fragment key={r.key}>
|
||||
<button
|
||||
@@ -395,6 +400,7 @@ export function MenuList({
|
||||
}}
|
||||
type="button"
|
||||
role={r.checked !== undefined ? "menuitemcheckbox" : "menuitem"}
|
||||
aria-label={split ? r.label : undefined}
|
||||
aria-checked={r.checked}
|
||||
aria-current={r.current || undefined}
|
||||
aria-disabled={r.disabled || undefined}
|
||||
@@ -427,8 +433,15 @@ export function MenuList({
|
||||
{r.checked ? <Icon name="check" size={13} /> : r.icon ? <Icon name={r.icon} size={14} /> : null}
|
||||
</span>
|
||||
)}
|
||||
<span className={styles.label} title={r.hint ? undefined : r.label}>
|
||||
{r.label}
|
||||
<span className={clsx(styles.label, split > 0 && styles.splitLabel)} title={r.hint ? undefined : r.label}>
|
||||
{split ? (
|
||||
<>
|
||||
<span className={styles.labelStart}>{characters.slice(0, split).join("")}</span>
|
||||
<span className={styles.labelEnd}>{characters.slice(split).join("")}</span>
|
||||
</>
|
||||
) : (
|
||||
r.label
|
||||
)}
|
||||
</span>
|
||||
{r.shortcut && (
|
||||
<span className={styles.shortcut} title={r.shortcut}>
|
||||
|
||||
Reference in new issue
Block a user