fix(vcs): align the file revision chooser (#4919)

fix(vcs): align the file revision chooser
This commit is contained in:
l0ng-ai
2026-11-21 07:59:59 +08:00
committed by GitHub
parent 9467c4ea1b
commit d31699c86a
4 changed files with 180 additions and 20 deletions
+104
View File
@@ -0,0 +1,104 @@
import { expect, ipcCalls, openFromTree, stubDesktop, test } from "./fixtures";
test("the file revision chooser previews commit messages and compares the selected revision", async ({
workbench: page,
}) => {
await openFromTree(page, "build.gradle.kts");
await stubDesktop(page);
await page.evaluate(async () => {
const root = "/dev/acme-api";
const path = `${root}/build.gradle.kts`;
const latest = "123abcd000000000000000000000000000000000";
const previous = "456efab000000000000000000000000000000000";
window.__ipc.handlers.vcs_revision_files = () => ["build.gradle.kts"];
window.__ipc.handlers.vcs_log = () => [
{
id: latest,
shortId: "123abcd",
author: "Lena Park",
timeMs: Date.now(),
summary: "Update reviewed totals",
message: "Update reviewed totals",
messageTruncated: true,
},
{
id: previous,
shortId: "456efab",
author: "Morgan Chen",
timeMs: Date.UTC(2025, 9, 18),
summary: "Include October adjustments",
message: "Include October adjustments\n\nUse the corrected quantities from the October review.",
},
];
window.__ipc.handlers.vcs_log_details_batch = () => [
{ message: "Update reviewed totals\n\nUse the totals reviewed by the release team." },
];
window.__ipc.handlers.vcs_file_at = () => "val reviewedTotal = 28\n";
window.__ipc.handlers.vcs_file_mode = () => "100644";
const storeModule = "/src/features/vcs/store.ts";
const historyModule = "/src/features/vcs/fileRevisions.ts";
const contextModule = "/src/platform/context.ts";
const actionsModule = "/src/platform/actions.ts";
const { useVcs } = await import(/* @vite-ignore */ storeModule);
const { hasFileHistory, trackFileHistory } = await import(/* @vite-ignore */ historyModule);
const { setContext } = await import(/* @vite-ignore */ contextModule);
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
useVcs.setState({ roots: [root], heads: { [root]: { headCommit: latest } }, statusLoaded: true });
trackFileHistory();
await expectFileHistory();
setContext("vcsAvailable", true);
await executeAction("vcs.compareWithRevision", path);
async function expectFileHistory() {
for (let i = 0; i < 20 && !hasFileHistory(path); i++) {
await new Promise((resolve) => setTimeout(resolve, 10));
}
if (!hasFileHistory(path)) throw new Error("The sample file has no tracked history");
}
});
const chooser = page.getByRole("dialog", { name: "Compare with Revision…" });
const search = chooser.getByRole("textbox", { name: "Search file revisions" });
const revisions = chooser.getByRole("listbox", { name: "File revisions" });
const message = chooser.getByRole("region", { name: "Commit message" });
await expect(revisions.getByRole("option")).toHaveCount(2);
await expect(message).toContainText("Use the totals reviewed by the release team.");
await expect
.poll(() => ipcCalls(page, "vcs_log_details_batch"))
.toEqual([
expect.objectContaining({
repo: "/dev/acme-api",
revisions: ["123abcd000000000000000000000000000000000"],
}),
]);
const firstAuthor = await revisions.getByText("Lena Park", { exact: true }).boundingBox();
const secondAuthor = await revisions.getByText("Morgan Chen", { exact: true }).boundingBox();
expect(Math.abs(firstAuthor!.x - secondAuthor!.x)).toBeLessThan(1);
await search.press("Tab");
await expect(message).toBeFocused();
await search.press("ArrowDown");
await expect(revisions.getByRole("option", { name: /Morgan Chen/ })).toHaveAttribute("aria-selected", "true");
await expect(message).toContainText("Use the corrected quantities from the October review.");
await page.setViewportSize({ width: 480, height: 350 });
const listBox = (await revisions.boundingBox())!;
const messageBox = (await message.boundingBox())!;
expect(messageBox.y).toBeGreaterThanOrEqual(listBox.y + listBox.height - 1);
expect(messageBox.y + messageBox.height).toBeLessThanOrEqual(350);
await search.fill("unmatched");
await expect(revisions).toContainText("No commits");
await expect(message).not.toContainText("Use the corrected quantities from the October review.");
await search.fill("October adjustments");
await expect(revisions.getByRole("option")).toHaveCount(1);
await expect(message).toContainText("Use the corrected quantities from the October review.");
await search.press("Enter");
await expect(chooser).toBeHidden();
await expect
.poll(() => ipcCalls(page, "vcs_file_at"))
.toContainEqual({
path: "/dev/acme-api/build.gradle.kts",
rev: "456efab000000000000000000000000000000000",
});
});
+40 -15
View File
@@ -1,23 +1,31 @@
.search {
padding: 8px 10px;
border-bottom: 1px solid var(--border-popup);
}
.body {
height: 280px;
.dialog > [data-dialog-body] {
display: flex;
flex-direction: column;
padding: 4px 0;
overflow: hidden;
}
.search {
flex: none;
padding: var(--space-2) var(--space-3);
border-bottom: 1px solid var(--border-popup);
}
.revisions {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
padding-block: var(--space-1);
}
.list {
flex: 1;
min-height: 0;
}
.error {
padding: 8px 10px;
padding: var(--space-2) var(--space-3);
color: var(--danger);
}
.row {
display: flex;
display: grid;
grid-template-columns: 9ch minmax(0, min(45%, 14em)) minmax(0, 1fr);
align-items: center;
gap: var(--space-3);
min-width: 0;
@@ -29,18 +37,35 @@
}
.date {
color: var(--fg-subtle);
flex-shrink: 0;
font-variant-numeric: tabular-nums;
}
.author {
flex: 0 0 110px;
color: var(--fg-secondary);
}
.author,
.subject {
.row > span {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.subject {
flex: 1;
.details {
flex: 0 0 min(40%, 144px);
min-height: 0;
overflow: auto;
padding: var(--space-2) var(--space-3) var(--space-3);
border-top: 1px solid var(--border-popup);
font-size: var(--fs-ui);
}
.details:focus-visible {
outline: 1px solid var(--accent);
outline-offset: -2px;
}
.caption {
margin-bottom: var(--space-2);
color: var(--fg-secondary);
}
.message {
color: var(--fg-strong);
line-height: 1.4;
white-space: pre-wrap;
overflow-wrap: anywhere;
}
+35 -5
View File
@@ -2,12 +2,14 @@ import { useEffect, useState, type KeyboardEvent } from "react";
import type { Commit } from "@/bindings";
import { call, commands, nextRequestId } from "@/platform/ipc";
import { tx } from "@/platform/i18n";
import { Dialog, List, SearchField, Spinner, T, listNavigate } from "@/ui";
import { Dialog, List, SearchField, Spinner, T, listNavigate, selectableText } from "@/ui";
import { openDialog } from "./dialogs";
import { annotateAtRevision } from "./annotateRevision";
import { openVcsDiff } from "./diffInput";
import { hasFileHistory } from "./fileRevisions";
import { useCommitDetails } from "./logDetails";
import { formatTime } from "./model";
import type { RepoCommit } from "./multiRoot";
import { repositoryPath } from "./repositoryPaths";
import { repoOf } from "./store";
import styles from "./FileRevisionChooser.module.css";
@@ -59,6 +61,15 @@ export function annotateFileRevision(path: string | null | undefined) {
));
}
function CommitMessage({ commit }: { commit: RepoCommit }) {
const { details } = useCommitDetails(commit, commit.messageTruncated === true);
return (
<div className={`${styles.message} ${selectableText}`}>
{details?.message ?? (commit.message || commit.summary)}
</div>
);
}
function FileRevisionChooser({
path,
repo,
@@ -109,6 +120,7 @@ function FileRevisionChooser({
`${c.id} ${formatTime(c.timeMs)} ${c.author} ${c.summary}`.toLocaleLowerCase().includes(q),
);
const idx = Math.min(active, items.length - 1);
const selected = items[idx];
const onKeyDown = (e: KeyboardEvent) => {
if (e.key === "Enter") {
e.preventDefault();
@@ -122,7 +134,16 @@ function FileRevisionChooser({
}
};
return (
<Dialog open title={title ?? "Compare with Revision…"} onClose={onClose} width={720} position="top">
<Dialog
open
title={title ?? "Compare with Revision…"}
onClose={onClose}
resizable="both"
initialSize={{ w: 600, h: 412 }}
minWidth={320}
minHeight={280}
className={styles.dialog}
>
<div className={styles.search}>
<SearchField
data-autofocus
@@ -137,7 +158,7 @@ function FileRevisionChooser({
variant="bare"
/>
</div>
<div className={styles.body}>
<div className={styles.revisions}>
{error ? (
<div className={styles.error} role="alert">
{error}
@@ -153,7 +174,6 @@ function FileRevisionChooser({
onActivate={onChoose}
focusable={false}
hoverSelects
rowHeight={28}
aria-label="File revisions"
empty={<T>No commits</T>}
className={styles.list}
@@ -162,12 +182,22 @@ function FileRevisionChooser({
<span className={styles.hash}>{c.shortId}</span>
<span className={styles.date}>{formatTime(c.timeMs)}</span>
<span className={styles.author}>{c.author}</span>
<span className={styles.subject}>{c.summary}</span>
</span>
)}
/>
)}
</div>
<section
key={selected?.id}
className={styles.details}
aria-label={tx("Commit message")}
tabIndex={selected ? 0 : undefined}
>
<div className={styles.caption} aria-hidden="true">
<T>Commit message</T>
</div>
{selected && <CommitMessage commit={{ ...selected, repo }} />}
</section>
</Dialog>
);
}
+1
View File
@@ -458,6 +458,7 @@
"Show File at Revision": "Show File at Revision",
"Search file revisions": "Search file revisions",
"File revisions": "File revisions",
"Commit message": "Commit message",
"The current line has no committed revision": "The current line has no committed revision",
"JAR Application": "JAR Application",
"Run an executable JAR": "Run an executable JAR",