mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
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.
This commit is contained in:
@@ -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();
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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) => <InteractiveRebaseDialog range={range} onClose={close} />);
|
||||
}
|
||||
|
||||
function promptMessage(title: string, initial: string): Promise<string | null> {
|
||||
function promptMessage(title: string, label: string, initial: string): Promise<string | null> {
|
||||
return new Promise((resolve) => {
|
||||
const close = openDialog(() => (
|
||||
<MessageDialog
|
||||
title={title}
|
||||
label={label}
|
||||
initial={initial}
|
||||
onDone={(m) => {
|
||||
close();
|
||||
@@ -376,30 +385,51 @@ function promptMessage(title: string, initial: string): Promise<string | null> {
|
||||
|
||||
function MessageDialog({
|
||||
title,
|
||||
label,
|
||||
initial,
|
||||
onDone,
|
||||
}: {
|
||||
title: string;
|
||||
label: string;
|
||||
initial: string;
|
||||
onDone: (message: string | null) => void;
|
||||
}) {
|
||||
const id = useId();
|
||||
const field = useRef<HTMLTextAreaElement>(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 (
|
||||
<Dialog
|
||||
open
|
||||
title={title}
|
||||
onClose={() => 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" },
|
||||
]}
|
||||
>
|
||||
<div className={styles.form}>
|
||||
<div className={messageStyles.form}>
|
||||
<label className={messageStyles.label} htmlFor={id}>
|
||||
{label}
|
||||
</label>
|
||||
<textarea
|
||||
id={id}
|
||||
ref={field}
|
||||
data-autofocus
|
||||
aria-label={tx("Commit message")}
|
||||
className={styles.textarea}
|
||||
className={`${styles.textarea} ${messageStyles.editor}`}
|
||||
style={{
|
||||
fontFamily: family,
|
||||
fontSize: size,
|
||||
fontWeight: fontWeightOf(editor?.fontWeight, 400),
|
||||
lineHeight: editor?.lineHeight ? `${editor.lineHeight}px` : undefined,
|
||||
}}
|
||||
rows={8}
|
||||
value={message}
|
||||
onChange={(e) => setMessage(e.target.value)}
|
||||
|
||||
@@ -459,6 +459,11 @@
|
||||
"Search file revisions": "Search file revisions",
|
||||
"File revisions": "File revisions",
|
||||
"Commit message": "Commit message",
|
||||
"Edit Commit Message": "Edit Commit Message",
|
||||
"Edit message for commit {hash}": "Edit message for commit {hash}",
|
||||
"Edit message for commit {hash} by {author}": "Edit message for commit {hash} by {author}",
|
||||
"Squashed Commit Message": "Squashed Commit Message",
|
||||
"Edit message for squashed commit": "Edit message for squashed commit",
|
||||
"Merge options": "Merge options",
|
||||
"Modify options": "Modify options",
|
||||
"Rebase {head}": "Rebase {head}",
|
||||
|
||||
@@ -1108,6 +1108,11 @@
|
||||
"Commit Message Inspections": "提交消息检查",
|
||||
"Commit Options": "提交选项",
|
||||
"Commit message": "提交消息",
|
||||
"Edit Commit Message": "编辑提交消息",
|
||||
"Edit message for commit {hash}": "编辑提交 {hash} 的消息",
|
||||
"Edit message for commit {hash} by {author}": "编辑 {author} 的提交 {hash} 的消息",
|
||||
"Squashed Commit Message": "压缩后的提交消息",
|
||||
"Edit message for squashed commit": "编辑压缩后的提交消息",
|
||||
"Commit message is empty": "提交消息为空",
|
||||
"Commit:": "提交:",
|
||||
"Committed": "已提交",
|
||||
|
||||
Reference in New Issue
Block a user