Compare commits

...
3 changed files with 141 additions and 45 deletions

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import { expect, test } from "./fixtures";
test("Welcome keeps project search and actions on one row at a narrow width", async ({ workbench: page }) => {
await page.setViewportSize({ width: 1080, height: 700 });
await page.evaluate(async () => {
const projectPath = "/src/platform/project.ts";
const { useProject } = await import(/* @vite-ignore */ projectPath);
useProject.setState({ project: null, lightEdit: false });
});
const projects = page.getByRole("region", { name: "Projects", exact: true });
const search = projects.getByRole("textbox", { name: "Search projects" });
const list = projects.getByRole("listbox", { name: "Recent projects" });
const more = projects.getByRole("button", { name: "More Actions", exact: true });
const open = projects.getByRole("button", { name: "Open", exact: true });
await expect(list.getByRole("option")).toHaveCount(4);
await expect(more).toBeVisible();
await expect(open).toHaveText("Open");
await page.setViewportSize({ width: 440, height: 620 });
const boxes = await Promise.all([search.boundingBox(), open.boundingBox(), more.boundingBox()]);
expect(boxes[0]!.width).toBeGreaterThan(95);
for (const box of boxes.slice(1)) {
expect(Math.abs(box!.y + box!.height / 2 - (boxes[0]!.y + boxes[0]!.height / 2))).toBeLessThan(2);
expect(box!.x + box!.width).toBeLessThanOrEqual(440);
}
await expect(open.getByText("Open", { exact: true })).toBeHidden();
await expect.poll(() => projects.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
await search.fill("tokio");
await expect(list.getByRole("option")).toHaveCount(1);
await expect(list.getByRole("option")).toContainText("tokio");
await more.press("Enter");
const menu = page.getByRole("menu", { name: "More Actions" });
for (const label of ["New File", "Open File", "Remote Development"]) {
await expect(menu.getByRole("menuitem", { name: new RegExp(label) })).toBeVisible();
}
await page.keyboard.press("Escape");
await expect(menu).toBeHidden();
await expect(more).toBeFocused();
await expect(search).toHaveValue("tokio");
});
+54 -29
View File
@@ -12,6 +12,8 @@ import {
Icon,
IconButton,
Kbd,
Menu,
type MenuItem,
SearchField,
Spinner,
isPopupOpen,
@@ -27,40 +29,63 @@ import { tx } from "@/platform/i18n";
function HeaderButtons() {
const canClone = useActions((s) => s.actions.has("vcs.clone"));
const canRemote = useActions((s) => s.actions.has("remote.connect"));
const opening = useProject((s) => s.opening);
const canCreate = useActions((s) => s.actions.has("file.newProject"));
const openKey = shortcutLabel("file.openProject");
const [moreOpen, setMoreOpen] = useState(false);
const more = useRef<HTMLButtonElement>(null);
const primary = [
{ id: "file.newProject", label: "New Project", icon: "plus", available: canCreate, disabled: opening },
{
id: "file.openProject",
label: "Open",
icon: "folder-open",
title: openKey ? tx`Open (${openKey})` : undefined,
available: true,
disabled: opening,
},
{ id: "vcs.clone", label: "Clone Repository", icon: "branch", available: canClone },
];
const secondary: MenuItem[] = [
{ kind: "action", action: "file.newUntitled", label: "New File", disabled: opening },
{ kind: "action", action: "file.openFile", label: "Open File", disabled: opening },
{ kind: "action", action: "remote.connect", label: "Remote Development", disabled: opening },
];
return (
<div className={styles.headerButtons}>
<Button disabled={opening} onClick={() => void executeAction("file.newUntitled")}>
<T>New File</T>
</Button>
{canCreate && (
<Button disabled={opening} onClick={() => void executeAction("file.newProject")}>
<T>New Project</T>
</Button>
)}
<Button
disabled={opening}
onClick={() => void executeAction("file.openProject")}
title={openKey ? tx`Open (${openKey})` : "Open"}
>
<T>Open</T>
</Button>
<Button disabled={opening} onClick={() => void executeAction("file.openFile")}>
<T>Open File</T>
</Button>
{canClone && (
<Button onClick={() => void executeAction("vcs.clone")}>
<T>Clone Repository</T>
</Button>
)}
{canRemote && (
<Button disabled={opening} onClick={() => void executeAction("remote.connect")}>
<T>Remote Development</T>
</Button>
<div className={styles.headerButtons} role="group" aria-label={tx("Project actions")}>
{primary.map(
({ id, label, title, icon, available, disabled }) =>
available && (
<Button
key={id}
size="small"
icon={icon}
className={styles.headerAction}
title={title ?? label}
aria-label={tx(label)}
disabled={disabled}
onClick={() => void executeAction(id)}
>
<span className={styles.headerActionLabel}>{tx(label)}</span>
</Button>
),
)}
<IconButton
ref={more}
icon="more"
title="More Actions"
aria-haspopup="menu"
aria-expanded={moreOpen}
onClick={() => setMoreOpen((open) => !open)}
/>
<Menu
open={moreOpen}
onClose={() => setMoreOpen(false)}
anchor={more}
items={secondary}
placement="bottom-end"
aria-label="More Actions"
/>
</div>
);
}
+45 -16
View File
@@ -129,6 +129,7 @@
/* ---- Projects page ---------------------------------------------------- */
.projects {
container: welcome-projects / inline-size;
flex: 1;
min-height: 0;
display: flex;
@@ -138,30 +139,51 @@
flex: none;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: var(--space-3);
min-height: 76px;
margin-left: 14px;
padding: 12px 14px 12px 6px;
gap: var(--space-2);
margin: 0 var(--space-3);
padding: var(--space-3) var(--space-1);
box-shadow: inset 0 -1px 0 var(--border);
}
.search {
flex: 1 1 160px;
flex: 1;
min-width: 0;
}
/* Wraps in a narrow window, so no button is clipped. */
.headerButtons {
flex: 0 1 auto;
min-width: 0;
flex: none;
display: flex;
flex-wrap: wrap;
gap: var(--space-2);
align-items: center;
gap: var(--space-1);
}
.headerAction {
max-width: 146px;
}
.headerActionLabel {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
}
@container welcome-projects (max-width: 600px) {
.headerAction {
width: var(--h-control);
padding: 0;
}
.headerActionLabel {
display: none;
}
}
@container welcome-projects (max-width: 218px) {
.header {
flex-wrap: wrap;
}
.search {
flex-basis: 100%;
}
}
.projectList {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: 14px 16px 14px 24px;
padding: var(--space-2) var(--space-3) var(--space-3);
outline: none;
}
.noMatches {
@@ -174,7 +196,7 @@
display: flex;
align-items: flex-start;
gap: var(--space-3);
padding: 8px 10px;
padding: var(--space-2);
border-radius: var(--radius-popup);
cursor: default;
}
@@ -186,8 +208,11 @@
.projectSelected:hover {
background: color-mix(in srgb, var(--bg-list-selected) 70%, var(--bg-island));
}
.projectBadge {
margin-top: 1px;
.tile.projectBadge {
width: 32px;
height: 32px;
margin-top: var(--space-0-5);
font-size: var(--fs-ui);
}
/* A project group: one line, folds its projects. */
.group {
@@ -199,6 +224,7 @@
flex: 1;
min-width: 0;
color: var(--fg-strong);
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
@@ -214,7 +240,8 @@
min-width: 0;
display: flex;
flex-direction: column;
line-height: 20px;
gap: var(--space-0-5);
line-height: 18px;
}
.projectName {
color: var(--fg-strong);
@@ -224,6 +251,7 @@
}
.projectPath {
color: var(--fg-muted);
font-size: var(--fs-small);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
@@ -234,6 +262,7 @@
gap: var(--space-1-5);
min-width: 0;
color: var(--fg-muted);
font-size: var(--fs-small);
--icon-color: var(--fg-muted);
}
.projectBranchName {