diff --git a/e2e/pushTargetBranch.spec.ts b/e2e/pushTargetBranch.spec.ts index 42f328798f..d5080f63e0 100644 --- a/e2e/pushTargetBranch.spec.ts +++ b/e2e/pushTargetBranch.spec.ts @@ -176,7 +176,29 @@ test("Push keeps commit subjects and changed files readable in a narrow window", await expect(input).toHaveValue("main"); await expect(dialog.getByRole("button", { name: "Push", exact: true })).toBeInViewport(); const details = dialog.getByRole("region", { name: "Commit details" }); - await expect(details).toContainText("Keep the new totals consistent with receipts."); + await page.evaluate(async () => { + const project = "/src/platform/project.ts"; + const { useProject } = await import(/* @vite-ignore */ project); + const { settings } = useProject.getState(); + useProject.setState({ + settings: { + ...settings, + editor: { ...settings?.editor, fontFamily: "Consolas", fontSize: 18, fontWeight: 400, boldFontWeight: 700 }, + }, + }); + }); + const messageSubject = details.getByText(OUTGOING, { exact: true }); + const messageBody = details.getByText("Keep the new totals consistent with receipts.", { exact: true }); + await expect(messageSubject).toHaveCSS("font-weight", "700"); + await expect(messageBody).toHaveCSS("font-weight", "400"); + await expect(messageSubject).toHaveCSS("font-size", "18px"); + await expect(messageBody).toHaveCSS("font-size", "18px"); + await expect(messageBody).toHaveCSS("font-family", /Consolas/); + const metadata = details.getByText(/Sam Rivera /); + await expect(metadata).toHaveCSS("font-size", "12px"); + await metadata.scrollIntoViewIfNeeded(); + await expect(metadata).toBeInViewport(); + expect(await details.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1); await expect .poll(async () => { const [tree, message] = await Promise.all([files.boundingBox(), details.boundingBox()]); diff --git a/src/features/vcs/CommitMessageContent.tsx b/src/features/vcs/CommitMessageContent.tsx new file mode 100644 index 0000000000..14d57b3920 --- /dev/null +++ b/src/features/vcs/CommitMessageContent.tsx @@ -0,0 +1,43 @@ +import type { Commit } from "@/bindings"; +import type { ReactNode } from "react"; +import { fontWeightOf } from "@/platform/editorSettings"; +import { resolveMonoFont } from "@/platform/fonts"; +import { tx } from "@/platform/i18n"; +import { useProject } from "@/platform/project"; +import styles from "./GitLog.module.css"; + +export function CommitMessageContent({ + commit, + message, + compact = false, + renderText = (text) => text, + revision = commit.shortId, +}: { + commit: Commit; + message: string; + compact?: boolean; + renderText?: (text: string) => ReactNode; + revision?: ReactNode; +}) { + const editor = useProject((s) => s.settings?.editor); + const { family, size } = resolveMonoFont(undefined, editor); + const [subject = "", ...bodyLines] = message.trimEnd().split("\n"); + const body = compact ? "" : bodyLines.join("\n").replace(/^\n+/, ""); + return ( + <> +
+
+ {renderText(subject)} +
+ {body &&
{renderText(body)}
} +
+
+ {revision} {commit.author} <{commit.email}> + {commit.timeMs ? " " + tx`on ${new Date(commit.timeMs).toLocaleString()}` : ""} +
+ + ); +} diff --git a/src/features/vcs/PushChanges.tsx b/src/features/vcs/PushChanges.tsx index 49aa2bb9b2..b9b2736a5a 100644 --- a/src/features/vcs/PushChanges.tsx +++ b/src/features/vcs/PushChanges.tsx @@ -10,6 +10,7 @@ import { executeAction } from "@/platform/actions"; import { call, commands } from "@/platform/ipc"; import { tx } from "@/platform/i18n"; import { Button, IconButton, Spinner, SplitGroup, SplitHandle, SplitPanel, T } from "@/ui"; +import { CommitMessageContent } from "./CommitMessageContent"; import { ComparisonTree } from "./ComparisonTree"; import { buildFileTree } from "./fileTree"; import { flatFileNodes, toLogChanges, type LogChange } from "./logChanges"; @@ -151,14 +152,9 @@ export function PushChanges({ /** The selected commit's full message, revision, author and time. */ function PushCommitDetails({ commit }: { commit: Commit }) { - const date = commit.timeMs ? new Date(commit.timeMs).toLocaleString() : null; return (
-
{commit.message.trimEnd() || commit.summary}
-
- {commit.shortId} {commit.author} <{commit.email}> - {date ? " " + tx`on ${date}` : ""} -
+
); } diff --git a/src/features/vcs/__tests__/pushChanges.test.tsx b/src/features/vcs/__tests__/pushChanges.test.tsx index f32e7b25bf..529ed79339 100644 --- a/src/features/vcs/__tests__/pushChanges.test.tsx +++ b/src/features/vcs/__tests__/pushChanges.test.tsx @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from "vitest"; -import { fireEvent, render, screen } from "@testing-library/react"; +import { fireEvent, render, screen, within } from "@testing-library/react"; import type { Commit } from "@/bindings"; const { files, combined, executeAction } = vi.hoisted(() => ({ @@ -69,8 +69,10 @@ describe("Push dialog changes", () => { const one = { ...older, message: "Add order service\n\nIntroduces the service.\n", timeMs: 1_700_000_000_000 }; render(); const details = screen.getByRole("region", { name: "Commit details" }); - expect(details.textContent).toContain("Add order service\n\nIntroduces the service."); - expect(details.textContent).toContain("aaaaaaa me on "); + const message = within(details); + expect(message.getByText("Add order service", { exact: true })).toBeTruthy(); + expect(message.getByText("Introduces the service.", { exact: true })).toBeTruthy(); + expect(message.getByText(/^aaaaaaa me on /)).toBeTruthy(); expect(await screen.findByText("src/orders")).toBeTruthy(); expect(screen.getAllByRole("treeitem")).toHaveLength(2); const grouping = screen.getByRole("button", { name: "Group by Directory" }); diff --git a/src/features/vcs/common.module.css b/src/features/vcs/common.module.css index e998179b43..20a2be8894 100644 --- a/src/features/vcs/common.module.css +++ b/src/features/vcs/common.module.css @@ -363,9 +363,6 @@ .pushCommitDetails { flex: 1; min-height: 0; - display: flex; - flex-direction: column; - gap: var(--space-1); margin: var(--space-1) var(--space-3); padding: var(--space-1) var(--space-2); overflow: auto; @@ -374,11 +371,6 @@ -webkit-user-select: text; user-select: text; } -.pushCommitMessage { - color: var(--fg-strong); - white-space: pre-wrap; - overflow-wrap: anywhere; -} .todoList { margin: 8px 0 0; padding-left: 18px; diff --git a/src/features/vcs/log/CommitMessage.tsx b/src/features/vcs/log/CommitMessage.tsx index f021f1a7f1..389b378bde 100644 --- a/src/features/vcs/log/CommitMessage.tsx +++ b/src/features/vcs/log/CommitMessage.tsx @@ -1,10 +1,8 @@ import type { Commit } from "@/bindings"; import { writeClipboardText } from "@/platform/clipboard"; -import { fontWeightOf } from "@/platform/editorSettings"; -import { resolveMonoFont } from "@/platform/fonts"; import { tx } from "@/platform/i18n"; -import { useProject } from "@/platform/project"; import clsx from "clsx"; +import { CommitMessageContent } from "../CommitMessageContent"; import styles from "../GitLog.module.css"; import { IssueText } from "../issueLinks"; import { useCommitDetails } from "../logDetails"; @@ -50,39 +48,25 @@ export function RefLabels({ /** A commit's message and metadata; `compact` (one of several selected): without the body. */ export function CommitMessage({ commit, compact = false }: { commit: Commit; compact?: boolean }) { const { details, error } = useCommitDetails(commit, !compact); - const editor = useProject((s) => s.settings?.editor); - const { family, size } = resolveMonoFont(undefined, editor); const repo = commitRepo(commit) ?? currentRepo(); - const message = details?.message || commit.message; - const [subject, ...bodyLines] = message.replace(/\s+$/, "").split("\n"); - const body = compact ? "" : bodyLines.join("\n").replace(/^\n+/, ""); return (
-
-
- -
- {body && ( -
- -
- )} -
-
- {" "} - {commit.author} <{commit.email}> - {commit.timeMs ? " " + tx`on ${new Date(commit.timeMs).toLocaleString()}` : ""} -
+ } + revision={ + + } + /> {!compact && commit.committer && (commit.committer !== commit.author ||