From d89991168e29d93a74c09f87df6fe3d7cdce8906 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sat, 21 Nov 2026 11:39:42 +0800 Subject: [PATCH] fix(vcs): align the history commit message dialog (#4945) Show the commit hash and author above the message editor when editing a commit. Use the same layout for the message of a squashed commit. The dialog resizes in both directions, and the text area follows the configured editor font, weight and line height. --- e2e/gitCommitMessageLayout.spec.ts | 99 +++++++++++++++++++ .../vcs/CommitMessageDialog.module.css | 27 +++++ src/features/vcs/rebase.tsx | 46 +++++++-- src/platform/locales/text/en.json | 5 + src/platform/locales/text/zh.json | 5 + 5 files changed, 174 insertions(+), 8 deletions(-) create mode 100644 e2e/gitCommitMessageLayout.spec.ts create mode 100644 src/features/vcs/CommitMessageDialog.module.css diff --git a/e2e/gitCommitMessageLayout.spec.ts b/e2e/gitCommitMessageLayout.spec.ts new file mode 100644 index 000000000..0847eecc9 --- /dev/null +++ b/e2e/gitCommitMessageLayout.spec.ts @@ -0,0 +1,99 @@ +import { expect, ipcCalls, stubDesktop, test } from "./fixtures"; + +test("the history message editor shows commit context and grows with the dialog", async ({ workbench: page }) => { + const author = "Sam Rivera"; + const earlier = "Keep the settlement audit trail"; + const latest = "Finalize the settlement report"; + const detail = "Preserve the original export for review."; + await page.setViewportSize({ width: 1120, height: 760 }); + await stubDesktop(page); + await page.evaluate( + async ({ author, earlier, latest, detail }) => { + const root = "/dev/acme-api"; + const head = "c".repeat(40); + const branch = { head: "main", headCommit: head, upstream: null, ahead: 0, behind: 0, operation: null }; + const commits = [ + { id: head, shortId: "cccccccc", parents: ["b".repeat(40)], summary: latest }, + { id: "b".repeat(40), shortId: "bbbbbbbb", parents: ["a".repeat(40)], summary: earlier }, + ].map((commit) => ({ + ...commit, + author, + email: "sam@example.invalid", + refs: [], + timeMs: 1795100200000, + message: commit.summary + "\n\n" + detail, + })); + const handlers = window.__ipc.handlers; + handlers.vcs_roots = () => [{ root, ...branch }]; + handlers.vcs_branch_info = () => branch; + handlers.vcs_status = () => []; + handlers.vcs_log = ({ query }) => + (query as { range: string | null }).range?.startsWith("b".repeat(40)) ? commits.slice(0, 1) : commits; + handlers.vcs_log_refs = () => ({}); + handlers.vcs_log_users = () => [author]; + handlers.vcs_config_get = () => null; + handlers.vcs_commit_files = () => []; + handlers.vcs_log_details_batch = () => []; + handlers.vcs_reword = () => ({ before: head, after: "d".repeat(40) }); + + const projectPath = "/src/platform/project.ts"; + const { useProject } = await import(/* @vite-ignore */ projectPath); + const settings = useProject.getState().settings; + useProject.setState({ settings: { ...settings, editor: { ...settings?.editor, fontSize: 16 } } }); + const vcsPath = "/src/features/vcs/store.ts"; + const { useVcs } = await import(/* @vite-ignore */ vcsPath); + useVcs.setState({ available: true, root, repo: root, roots: [root], branchesLoaded: true }); + const contextPath = "/src/platform/context.ts"; + (await import(/* @vite-ignore */ contextPath)).setContext("vcsAvailable", true); + const actionsPath = "/src/platform/actions.ts"; + await (await import(/* @vite-ignore */ actionsPath)).executeAction("vcs.showLog"); + }, + { author, earlier, latest, detail }, + ); + + const log = page.getByRole("listbox", { name: "Commits" }); + const newest = log.getByRole("option", { name: new RegExp(latest) }); + const older = log.getByRole("option", { name: new RegExp(earlier) }); + await newest.click({ button: "right" }); + await page.getByRole("menuitem", { name: /Edit Commit Message/ }).click(); + const edit = page.getByRole("dialog", { name: /^Edit Commit Message/ }); + const context = "Edit message for commit cccccccc by " + author; + await expect(edit.getByText(context, { exact: true })).toBeVisible(); + const message = edit.getByRole("textbox", { name: context }); + await expect(message).toBeFocused(); + await expect(message).toHaveValue(latest + "\n\n" + detail); + await expect(message).toHaveCSS("font-size", "16px"); + + const grip = edit.getByRole("separator", { name: "Resize" }); + const before = (await message.boundingBox())!; + const corner = (await grip.boundingBox())!; + await page.mouse.move(corner.x + corner.width / 2, corner.y + corner.height / 2); + await page.mouse.down(); + await page.mouse.move(corner.x + corner.width / 2 + 72, corner.y + corner.height / 2 + 40); + await page.mouse.up(); + await expect.poll(async () => (await message.boundingBox())!.width).toBeGreaterThan(before.width + 60); + await expect.poll(async () => (await message.boundingBox())!.height).toBeGreaterThan(before.height + 30); + + const ok = edit.getByRole("button", { name: "OK", exact: true }); + await message.fill(" "); + await expect(ok).toBeDisabled(); + const revised = "Finalize the reviewed settlement report\n\n" + detail; + await message.fill(revised); + await ok.click(); + await expect + .poll(() => ipcCalls(page, "vcs_reword")) + .toEqual([{ repo: "/dev/acme-api", commit: "c".repeat(40), message: revised }]); + + await newest.click(); + await older.click({ modifiers: ["Shift"] }); + await newest.click({ button: "right" }); + await page.getByRole("menuitem", { name: /Squash Commits/ }).click(); + const squash = page.getByRole("dialog", { name: "Squashed Commit Message" }); + const combined = squash.getByRole("textbox", { name: "Edit message for squashed commit" }); + await expect(combined).toHaveValue([earlier, detail, latest, detail].join("\n\n")); + await page.setViewportSize({ width: 420, height: 490 }); + await expect(combined).toBeInViewport({ ratio: 1 }); + await expect(squash.getByRole("button", { name: "OK", exact: true })).toBeInViewport({ ratio: 1 }); + await squash.getByRole("button", { name: "Cancel", exact: true }).click(); + await expect(squash).toBeHidden(); +}); diff --git a/src/features/vcs/CommitMessageDialog.module.css b/src/features/vcs/CommitMessageDialog.module.css new file mode 100644 index 000000000..2a2adf514 --- /dev/null +++ b/src/features/vcs/CommitMessageDialog.module.css @@ -0,0 +1,27 @@ +.dialog > [data-dialog-body] { + display: flex; + flex-direction: column; +} + +.form { + display: flex; + flex: 1; + flex-direction: column; + gap: var(--space-2); + padding: var(--space-3) var(--space-4) 0; +} + +.label { + font-size: var(--fs-ui); + color: var(--fg-secondary); + overflow-wrap: anywhere; +} + +.form .editor { + flex: 1; + width: 100%; + min-height: 60px; + padding: var(--space-2); + resize: none; + line-height: 1.55; +} diff --git a/src/features/vcs/rebase.tsx b/src/features/vcs/rebase.tsx index 99ab89410..09ccad320 100644 --- a/src/features/vcs/rebase.tsx +++ b/src/features/vcs/rebase.tsx @@ -3,9 +3,12 @@ import { commitRepo } from "./multiRoot"; * Git Log history rewriting: Undo Commit, Edit Commit Message, Drop Commit and * Interactively Rebase from Here (IDEA's Git.Log.ContextMenu). */ -import { useLayoutEffect, useRef, useState } from "react"; +import { useId, useLayoutEffect, useRef, useState } from "react"; import type { BranchInfo, Commit, RebaseAction, RebaseEntry } from "@/bindings"; +import { fontWeightOf } from "@/platform/editorSettings"; +import { resolveMonoFont } from "@/platform/fonts"; import { call, commands } from "@/platform/ipc"; +import { useProject } from "@/platform/project"; import { Dialog, IconButton, Select, SplitGroup, SplitHandle, SplitPanel, T } from "@/ui"; import { workflowSettings } from "@/platform/workflowSettings"; import { ask, showError } from "@/workbench/messages"; @@ -37,6 +40,7 @@ import { currentRepo, refreshNow, useVcs } from "./store"; import { isProtectedBranch } from "./remoteUi"; import { notifications } from "@/workbench/contributions"; import styles from "./common.module.css"; +import messageStyles from "./CommitMessageDialog.module.css"; import { tx } from "@/platform/i18n"; const short = (id: string) => id.slice(0, 8); @@ -226,7 +230,10 @@ export async function editCommitMessage(commit: Commit) { // A paged log only carries the summary line: load the full message so the // dialog edits subject and body, not the subject alone (#2238). const initial = commit.messageTruncated ? (await loadLogDetails(commit)).message : commit.message; - const message = await promptMessage(`Edit Commit Message (${short(commit.id)})`, initial); + const hash = short(commit.id); + const author = commit.author || commit.email; + const label = author ? tx`Edit message for commit ${hash} by ${author}` : tx`Edit message for commit ${hash}`; + const message = await promptMessage("Edit Commit Message", label, initial); if (message === null || message.trim() === initial.trim()) return; // Written without a rebase: the index and the working tree (local changes) stay as they are. const change = await runOp(tx`Edit commit message of ${short(commit.id)}`, () => @@ -322,7 +329,8 @@ export async function squashCommits(commits: Commit[]) { const ids = new Set(commits.map((c) => c.id)); const oldestFirst = range.commits.filter((c) => ids.has(c.id)); const message = await promptMessage( - `Squash ${commits.length} Commits`, + "Squashed Commit Message", + tx("Edit message for squashed commit"), oldestFirst.map((c) => c.message.trim()).join("\n\n"), ); if (message === null || !message.trim()) return; @@ -359,11 +367,12 @@ export async function interactivelyRebaseFrom(target: Commit) { openDialog((close) => ); } -function promptMessage(title: string, initial: string): Promise { +function promptMessage(title: string, label: string, initial: string): Promise { return new Promise((resolve) => { const close = openDialog(() => ( { close(); @@ -376,30 +385,51 @@ function promptMessage(title: string, initial: string): Promise { function MessageDialog({ title, + label, initial, onDone, }: { title: string; + label: string; initial: string; onDone: (message: string | null) => void; }) { + const id = useId(); + const field = useRef(null); const [message, setMessage] = useState(initial); + const editor = useProject((s) => s.settings?.editor); + const { family, size } = resolveMonoFont(undefined, editor); + useLayoutEffect(() => field.current?.setSelectionRange(0, 0), []); + return ( onDone(null)} - width={520} + width={620} + minWidth={340} + resizable="both" + className={messageStyles.dialog} buttons={[ { label: "OK", role: "default", disabled: !message.trim(), onClick: () => onDone(message) }, { label: "Cancel", role: "cancel" }, ]} > -
+
+