Compare commits

...
Author SHA1 Message Date
l0ng-ai f6cc95de29 fix(search): keep action names and shortcuts readable 2026-11-22 19:05:58 +08:00
3 changed files with 74 additions and 2 deletions

No files matched your search

+54
View File
@@ -1,6 +1,60 @@
import { doubleShift, expect, stubDesktop, test } from "./fixtures";
import type { Page } from "@playwright/test";
test("action names stay readable beside shortcuts and categories", async ({ workbench: page }) => {
const titles = ["Reconcile warehouse totals", "Reconcile settlement exports"];
const shortcuts = await page.evaluate(async (titles) => {
const actionsModule = "/src/platform/actions.ts";
const keymapModule = "/src/platform/keymap.ts";
const { registerActions, executeAction } = await import(/* @vite-ignore */ actionsModule);
const platformModule = "/src/platform/platformInfo.ts";
const { registerExtensionBindings, shortcutLabel } = await import(/* @vite-ignore */ keymapModule);
const { usePlatform } = await import(/* @vite-ignore */ platformModule);
usePlatform.setState({ os: "windows" });
const ids = ["review.reconcileWarehouse", "review.reconcileSettlement"];
const bindings = ["Ctrl+K Ctrl+R", "Ctrl+Alt+Shift+PageDown Ctrl+Alt+Shift+PageUp"];
registerActions(
titles.map((title, index) => ({
id: ids[index]!,
title,
category: "Warehouse reconciliation and settlement reports",
icon: "check",
run: () => document.body.setAttribute("data-review-action", title),
})),
);
ids.forEach((id, index) => registerExtensionBindings(id, [bindings[index]!]));
await executeAction("navigate.findAction");
return ids.map((id) => shortcutLabel(id) as string);
}, titles);
const dialog = page.locator('[role="dialog"]:has(#se-query)');
await dialog.getByRole("combobox", { name: "Search query" }).fill("Reconcile");
for (const width of [400, 1120]) {
await page.setViewportSize({ width, height: 630 });
for (const [index, title] of titles.entries()) {
const row = dialog.getByRole("option").filter({ hasText: title });
const keys = row.getByText(shortcuts[index]!, { exact: true });
await expect(keys).toBeAttached();
const geometry = await keys.evaluate((el) => {
const name = el.previousElementSibling!.getBoundingClientRect();
const main = el.parentElement!.getBoundingClientRect();
const key = el.getBoundingClientRect();
return { name: name.width, inside: key.left >= name.right && key.right <= main.right + 1 };
});
expect(geometry.name).toBeGreaterThanOrEqual(80);
expect(geometry.inside).toBe(true);
await expect(keys).toHaveCSS("font-size", "12px");
await expect(keys).toHaveCSS("font-weight", "600");
await expect(keys).toHaveAttribute("title", shortcuts[index]!);
if (index === 0) expect(await keys.evaluate((el) => el.scrollWidth <= el.clientWidth)).toBe(true);
}
}
await dialog.getByRole("option").filter({ hasText: titles[1]! }).click();
await expect(dialog).toBeHidden();
await expect(page.locator("body")).toHaveAttribute("data-review-action", titles[1]!);
});
async function searchFiles(page: Page) {
await stubDesktop(page);
await page.evaluate(() => {
@@ -227,8 +227,14 @@
}
.shortcut {
flex: none;
max-width: 55%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--fg-subtle);
font-family: var(--font-keys);
font-size: var(--fs-small);
font-weight: 600;
}
.right {
flex: none;
@@ -249,6 +255,9 @@
align-items: center;
gap: var(--space-1-5);
}
.actionRow > .right {
max-width: 30%;
}
.disabled .name,
.disabled .location,
.disabled .shortcut,
@@ -872,11 +872,16 @@ function ResultRow({
<span
className={clsx(styles.actionRow, !row.enabled && styles.disabled)}
aria-disabled={!row.enabled || undefined}
title={row.title}
>
<span className={styles.icon}>{row.icon ? <Icon name={row.icon} size={16} /> : null}</span>
<span className={styles.main}>
<HighlightedText className={styles.name} text={row.title} indices={row.indices} tone={tone} />
{shortcut && <span className={styles.shortcut}>{shortcut}</span>}
{shortcut && (
<kbd className={styles.shortcut} title={shortcut}>
{shortcut}
</kbd>
)}
</span>
{toggled !== undefined ? (
<span
@@ -896,7 +901,11 @@ function ResultRow({
/>
</span>
) : (
row.category && <span className={styles.right}>{row.category}</span>
row.category && (
<span className={styles.right} title={row.category}>
{row.category}
</span>
)
)}
</span>
);