From 3080dc610016ea0a42559db44c0ea91baf4712b4 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Mon, 23 Nov 2026 11:45:46 +0800 Subject: [PATCH] fix(editor): balance the Edit Macros panes (#5293) Edit Macros starts with equal widths for the macro list and recorded steps. The keyboard-resizable divider remembers its position. Rename and Delete sit in the toolbar above the macro list, and the dialog opens with focus on the list. Recorded steps use the UI font and wrap within their pane. --- e2e/macroEditorLayout.spec.ts | 56 ++++++++++++++++++ src/features/macros/MacrosDialog.tsx | 82 ++++++++++++++++----------- src/features/macros/macros.module.css | 46 ++++++++------- 3 files changed, 130 insertions(+), 54 deletions(-) create mode 100644 e2e/macroEditorLayout.spec.ts diff --git a/e2e/macroEditorLayout.spec.ts b/e2e/macroEditorLayout.spec.ts new file mode 100644 index 000000000..ce16668d3 --- /dev/null +++ b/e2e/macroEditorLayout.spec.ts @@ -0,0 +1,56 @@ +import type { Page } from "@playwright/test"; +import { expect, test } from "./fixtures"; + +async function editMacros(page: Page) { + await page.evaluate(async () => { + const actions = "/src/platform/actions.ts"; + if (!(await (await import(/* @vite-ignore */ actions)).executeAction("macro.edit"))) throw Error("Edit Macros"); + }); +} + +test("Edit Macros keeps a balanced, resizable split for names and recorded steps", async ({ workbench: page }) => { + await page.evaluate(async () => { + const model = "/src/features/macros/model.ts"; + const { saveMacro } = await import(/* @vite-ignore */ model); + saveMacro("Insert comment", [{ kind: "text", text: "Review this block" }]); + saveMacro("Wrap selection", [ + { kind: "key", key: "Home" }, + { kind: "text", text: "beginProcessingCurrentSelectionImmediately();".repeat(6) }, + { kind: "key", key: "End" }, + ]); + }); + await editMacros(page); + + const editor = page.getByRole("dialog", { name: "Edit Macros", exact: true }); + const macros = editor.getByRole("listbox", { name: "Macros" }); + const steps = editor.getByRole("list", { name: "Recorded steps" }); + const options = editor.getByRole("toolbar", { name: "Macros" }); + const divider = editor.getByRole("separator", { name: "Macros" }); + const [initial, stepsWidth] = await editor.evaluate((dialog) => [ + dialog.querySelector('[role="listbox"]')!.getBoundingClientRect().width, + dialog.querySelector("ol")!.getBoundingClientRect().width, + ]); + expect(Math.abs(initial - stepsWidth)).toBeLessThanOrEqual(1); + await expect(macros).toBeFocused(); + expect((await steps.boundingBox())!.height).toBeGreaterThan(260); + expect((await options.boundingBox())!.y).toBeLessThan((await macros.boundingBox())!.y); + + await macros.getByRole("option", { name: "Wrap selection" }).click(); + await expect(steps.getByText("Press Home")).toBeVisible(); + await divider.press("ArrowRight"); + await expect.poll(async () => (await macros.boundingBox())!.width).toBeGreaterThan(initial + 5); + const resized = (await macros.boundingBox())!.width; + await editor.locator("[data-dialog-footer]").getByRole("button", { name: "Close" }).click(); + await editMacros(page); + await expect.poll(async () => (await macros.boundingBox())!.width).toBeCloseTo(resized, 0); + + await page.setViewportSize({ width: 400, height: 620 }); + await macros.getByRole("option", { name: "Wrap selection" }).click(); + expect(await steps.evaluate((list) => list.scrollWidth - list.clientWidth)).toBeLessThanOrEqual(1); + await options.getByRole("button", { name: "Rename Macro" }).click(); + const rename = page.getByRole("dialog", { name: "Rename Macro", exact: true }); + await rename.getByRole("textbox").fill("Wrap text"); + await rename.getByRole("button", { name: "Rename", exact: true }).click(); + await expect(macros.getByRole("option", { name: "Wrap text" })).toBeVisible(); + await expect(steps.getByText("Press Home")).toBeVisible(); +}); diff --git a/src/features/macros/MacrosDialog.tsx b/src/features/macros/MacrosDialog.tsx index 6842a82d2..fa33d5681 100644 --- a/src/features/macros/MacrosDialog.tsx +++ b/src/features/macros/MacrosDialog.tsx @@ -3,7 +3,7 @@ import { useState } from "react"; import { create } from "zustand"; import { executeAction, getAction } from "@/platform/actions"; import { t, tx } from "@/platform/i18n"; -import { BarButton, Button, Dialog, Icon, List, T } from "@/ui"; +import { BarButton, Dialog, Icon, IconButton, List, SplitGroup, SplitHandle, SplitPanel, T } from "@/ui"; import { confirm } from "@/workbench/messages"; import { promptInput } from "@/workbench/inputDialogs"; import { deleteMacro, describeStep, renameMacro, useMacros } from "./model"; @@ -80,37 +80,55 @@ function EditMacrosDialog({ onClose }: { onClose: () => void }) { buttons={[{ label: t("common.close"), role: "cancel" }]} >
-
- m.name} - activeIndex={Math.min(active, saved.length - 1)} - onActiveChange={setActive} - className={styles.list} - aria-label="Macros" - empty={ -
- No saved macros -
- } - renderItem={(m) =>
{m.name}
} - /> -
- - -
-
-
    - {macro?.steps.map((step, i) => ( -
  1. - {describeStep(step, actionTitle)} -
  2. - ))} -
+ + +
+ void remove()} + /> + void rename()} + /> +
+ m.name} + activeIndex={Math.min(active, saved.length - 1)} + onActiveChange={setActive} + autoFocus + className={styles.list} + aria-label="Macros" + empty={ +
+ No saved macros +
+ } + renderItem={(m) => ( +
+ {m.name} +
+ )} + /> +
+ + +
    + {macro?.steps.map((step, i) => ( +
  1. + {describeStep(step, actionTitle)} +
  2. + ))} +
+
+
); diff --git a/src/features/macros/macros.module.css b/src/features/macros/macros.module.css index 05d6733cb..b3937fffb 100644 --- a/src/features/macros/macros.module.css +++ b/src/features/macros/macros.module.css @@ -8,23 +8,27 @@ background: var(--danger); } .edit { - display: grid; - grid-template-columns: 220px 1fr; - gap: var(--space-3); - height: 300px; - padding: 14px; -} -.column { display: flex; flex-direction: column; - gap: var(--space-2); - min-height: 0; + height: 300px; + padding: var(--space-3); +} +.panes { + flex: 1; + border: 1px solid var(--border); + border-radius: var(--radius-control); +} +.toolbar { + display: flex; + flex: none; + align-items: center; + gap: var(--space-0-5); + padding: var(--space-1) var(--space-2); + border-bottom: 1px solid var(--border); } .list { flex: 1; min-height: 0; - border: 1px solid var(--border); - border-radius: var(--radius-control); } .row { padding: 0 8px; @@ -32,27 +36,25 @@ text-overflow: ellipsis; white-space: nowrap; } -.buttons { - display: flex; - gap: var(--space-1-5); -} .empty { padding: 6px 8px; color: var(--fg-subtle); font-size: var(--fs-small); } .steps { + flex: 1; + min-height: 0; margin: 0; - padding: 6px 8px 6px 32px; + padding: var(--space-2) var(--space-2) var(--space-2) 28px; overflow: auto; - border: 1px solid var(--border); - border-radius: var(--radius-control); - font-family: var(--font-mono); - font-size: var(--fs-code); + font-family: var(--font-ui); + font-size: var(--fs-ui); color: var(--fg); } .step { - line-height: 1.6; + min-height: var(--h-row); + padding-block: var(--space-0-5); + line-height: 1.5; white-space: pre-wrap; - word-break: break-word; + overflow-wrap: anywhere; }