From bd7613e149585a0181c30692c74ea1b2bbd79fb7 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Mon, 23 Nov 2026 02:31:15 +0800 Subject: [PATCH] fix(vcs): show readable commit message history previews --- e2e/commit.spec.ts | 44 +++++++++++++++++----- src/features/vcs/CommitView.module.css | 16 ++++++++ src/features/vcs/CommitView.tsx | 51 ++++++++++++++++---------- src/platform/locales/text/en.json | 1 + 4 files changed, 83 insertions(+), 29 deletions(-) diff --git a/e2e/commit.spec.ts b/e2e/commit.spec.ts index ca6c3859b5..13ba3f1247 100644 --- a/e2e/commit.spec.ts +++ b/e2e/commit.spec.ts @@ -1024,27 +1024,51 @@ test("the Commit tool window restores the draft and author options for the inclu await expect(message).toHaveValue("Default draft"); }); -test("commit message history opens above the message without an empty icon column", async ({ workbench: page }) => { +test("commit message history shows compact message previews above the editor", async ({ workbench: page }) => { + await page.emulateMedia({ reducedMotion: "reduce" }); await stubRepository(page); await page.keyboard.press("Meta+k"); const message = page.getByRole("textbox", { name: "Commit message" }); await expect(message).toBeVisible(); await page.evaluate((root) => { - localStorage.setItem(`openidea.vcs.commitMessages:${root}`, JSON.stringify(["Previous commit message"])); + localStorage.setItem( + `openidea.vcs.commitMessages:${root}`, + JSON.stringify([ + "Update inventory\n\nReview settlement totals", + "Update inventory\n\nReconcile export records", + ...Array.from({ length: 7 }, (_, index) => `Earlier message ${index + 1}`), + ]), + ); }, ROOT); await message.fill("Draft"); - await page.getByRole("button", { name: "Commit Message History" }).click(); + const history = page.getByRole("button", { name: "Commit Message History" }); + await history.click(); const menu = page.getByRole("menu", { name: "Recent commit messages" }); - const row = menu.getByRole("menuitem", { name: "Previous commit message" }); + const row = menu.getByRole("menuitem", { name: /Update inventory.*Review settlement totals/ }); await expect(row).toBeVisible(); - const messageBox = await message.boundingBox(); - const menuBox = await menu.locator("..").boundingBox(); - expect(messageBox).not.toBeNull(); - expect(menuBox).not.toBeNull(); - expect(menuBox!.y + menuBox!.height).toBeLessThan(messageBox!.y); - expect(Math.abs(menuBox!.x - messageBox!.x)).toBeLessThan(2); + const messageBox = (await message.boundingBox())!; + const menuBox = (await menu.locator("..").boundingBox())!; + const rowBox = (await row.boundingBox())!; + expect(messageBox.y - menuBox.y - menuBox.height).toBeCloseTo(3, 0); + expect(Math.abs(menuBox.x - messageBox.x)).toBeLessThan(2); + expect(menuBox.height).toBeLessThan(rowBox.height * 8); + await expect(row).toHaveCSS("font-family", await message.evaluate((el) => getComputedStyle(el).fontFamily)); + await expect(row).toHaveCSS("font-size", await message.evaluate((el) => getComputedStyle(el).fontSize)); await expect(row.locator("span")).toHaveCount(1); + + await row.press("Escape"); + await expect(menu).toBeHidden(); + await expect(message).toHaveValue("Draft"); + await history.click(); + await row.press("Home"); + await expect(row).toBeFocused(); + await page.keyboard.press("ArrowDown"); + const second = menu.getByRole("menuitem", { name: /Update inventory.*Reconcile export records/ }); + await expect(second).toBeFocused(); + await page.keyboard.press("Enter"); + await expect(message).toHaveValue("Update inventory\n\nReconcile export records"); + await expect(message).toBeFocused(); }); test("Amend shows the original author and warns when the committer differs", async ({ workbench: page }) => { diff --git a/src/features/vcs/CommitView.module.css b/src/features/vcs/CommitView.module.css index 708f11dc40..eddcd8cad4 100644 --- a/src/features/vcs/CommitView.module.css +++ b/src/features/vcs/CommitView.module.css @@ -134,6 +134,22 @@ gap: var(--space-0-5) var(--space-1); padding: var(--space-0-5) 6px var(--space-0-5) 12px; } +.messageHistory { + --history-row-height: max(var(--h-list-row), calc(1em + var(--space-2))); + min-width: min(180px, calc(100vw - var(--space-3))); + max-height: calc(7 * var(--history-row-height) + var(--space-2) + 2px); + padding-block: var(--space-1); + overflow-x: hidden; +} +.messageHistory [role="menu"] { + max-width: calc(var(--history-columns) + var(--space-4) + var(--space-2)); + font-size: inherit; +} +.messageHistory [role="menuitem"] { + height: var(--history-row-height); + margin-inline: var(--space-1); + padding-inline: var(--space-2); +} .amendTarget { min-width: 0; max-width: 112px; diff --git a/src/features/vcs/CommitView.tsx b/src/features/vcs/CommitView.tsx index e8bf6acbad..a81ff3ce41 100644 --- a/src/features/vcs/CommitView.tsx +++ b/src/features/vcs/CommitView.tsx @@ -29,7 +29,8 @@ import { EmptyState, Icon, IconButton, - Menu, + MenuList, + Popup, Spinner, SplitGroup, SplitHandle, @@ -1374,7 +1375,6 @@ export function CommitMessageField({ const amend = useCommit((s) => s.amend); const focusTick = useCommit((s) => s.focusTick); const ref = useRef(null); - const barRef = useRef(null); const [historyOpen, setHistoryOpen] = useState(false); const historyTick = useCommit((s) => s.historyTick); const { emptyError } = runner; @@ -1393,6 +1393,11 @@ export function CommitMessageField({ const cfg = useWorkflowSettings((s) => s.vcs.commit); const editor = useProject((s) => s.settings?.editor); const { family, size } = resolveMonoFont(undefined, editor); + const messageFont = { + fontFamily: family, + fontSize: size, + fontWeight: fontWeightOf(editor?.fontWeight, 400), + }; const first = message.split("\n")[0] ?? ""; const tooLong = cfg.limitSubject && first.length > cfg.subjectLimit; const problems = messageProblems(message, cfg).filter((p) => !p.startsWith("Subject line")); @@ -1402,7 +1407,7 @@ export function CommitMessageField({ return ( <> -
+
void setAmend(v)} label="Amend" /> {chooseAmendTarget && amendRoot && } setHistoryOpen((o) => !o)} /> - setHistoryOpen(false)} - anchor={barRef} + anchor={ref} placement="top-start" - iconColumn={false} - aria-label="Recent commit messages" - items={history.map((m, i) => ({ - id: `h${i}`, - label: m.split("\n")[0]!.slice(0, 80), - run: () => { - useCommit.setState({ message: m }); - ref.current?.focus(); - }, - }))} - /> + offset={3} + role="presentation" + autoFocus={false} + className={styles.messageHistory} + style={{ ...messageFont, ["--history-columns" as string]: `${cfg.subjectLimit}ch` }} + > + setHistoryOpen(false)} + iconColumn={false} + aria-label={tx("Recent commit messages")} + items={history.map((m, i) => ({ + id: `h${i}`, + label: m.replace(/\r\n?|\n/g, " ⏎ "), + verbatim: true, + run: () => { + useCommit.setState({ message: m }); + ref.current?.focus(); + }, + }))} + /> + {tooLong && ( @@ -1445,9 +1460,7 @@ export function CommitMessageField({ aria-invalid={emptyError || undefined} style={{ ["--guide" as string]: `${margin}ch`, - fontFamily: family, - fontSize: size, - fontWeight: fontWeightOf(editor?.fontWeight, 400), + ...messageFont, lineHeight: editor?.lineHeight ? `${editor.lineHeight}px` : undefined, }} value={message} diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index f2e25dd94e..dc575c605a 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -28,6 +28,7 @@ "The Git operation changed. Review the current changes and try again.": "The Git operation changed. Review the current changes and try again.", "Git operation has no current commit": "Git operation has no current commit", "Invalid commit message": "Invalid commit message", + "Recent commit messages": "Recent commit messages", "Invalid commit message file path": "Invalid commit message file path", "Review staged changes": "Review staged changes", "Commit and Continue": "Commit and Continue",