From 4eab243ef2ac66fe3da44e4a4191b79a59231622 Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Fri, 4 Dec 2026 19:44:43 +0900 Subject: [PATCH] fix(vcs): mark the active changelist bold and list it first (#8004) The Commit tool window meant to draw only the active changelist in bold, but the stylesheet only gave inactive lists font-weight 400, the weight every group label already has, so the active list looked like the others. Lists also appeared in creation order. The active list is now bold and comes first, the other lists follow by name in natural order, and Unversioned Files stays last. Refs #7433 Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com> --- src/features/vcs/CommitView.module.css | 4 +- src/features/vcs/CommitView.tsx | 2 +- .../vcs/__tests__/activeChangelist.test.tsx | 77 +++++++++++++++++++ src/features/vcs/changes.ts | 8 +- 4 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 src/features/vcs/__tests__/activeChangelist.test.tsx diff --git a/src/features/vcs/CommitView.module.css b/src/features/vcs/CommitView.module.css index 610d3d2777..a5c4fc5853 100644 --- a/src/features/vcs/CommitView.module.css +++ b/src/features/vcs/CommitView.module.css @@ -330,8 +330,8 @@ background: color-mix(in srgb, var(--accent) 12%, transparent); } /* Only the active change list is bold, as in IDEA. */ -.inactiveList { - font-weight: 400; +.activeList { + font-weight: 600; } .messageError { box-shadow: inset 0 0 0 1px var(--danger); diff --git a/src/features/vcs/CommitView.tsx b/src/features/vcs/CommitView.tsx index 51e3fef98e..ec3480ce75 100644 --- a/src/features/vcs/CommitView.tsx +++ b/src/features/vcs/CommitView.tsx @@ -1304,7 +1304,7 @@ export function ChangesTree({ mode, amended }: { mode: "commit" | "local" | "dia styles.label, n.type === "group" && styles.groupLabel, staging && n.type === "group" && styles.stageGroupLabel, - n.type === "group" && n.changelist && !n.active && styles.inactiveList, + n.type === "group" && n.changelist && n.active && styles.activeList, )} style={n.type === "file" && n.kind ? { color: KIND_COLOR[n.kind] } : undefined} {...(n.type === "file" && n.kind && tooltipAttrs(KIND_LABEL[n.kind]))} diff --git a/src/features/vcs/__tests__/activeChangelist.test.tsx b/src/features/vcs/__tests__/activeChangelist.test.tsx new file mode 100644 index 0000000000..c9e5684d4e --- /dev/null +++ b/src/features/vcs/__tests__/activeChangelist.test.tsx @@ -0,0 +1,77 @@ +/** + * Issue #7433: the active changelist stands out in the Commit tool window as in IDEA + * (ChangesBrowserChangeListNode): its name is bold and it comes first, the other lists + * follow by name, and Unversioned Files stays after them. + */ +import { render, screen } from "@testing-library/react"; +import { beforeEach, describe, expect, it, vi } from "vitest"; + +vi.mock("@/platform/ipc", async (importOriginal) => { + const real = await importOriginal(); + return { ...real, call: vi.fn(async () => null) }; +}); + +vi.mock("../DiffEditor", () => ({ DiffEditor: () =>
})); + +import type { ChangelistState } from "@/bindings"; +import { buildChangeTree } from "../changes"; +import { ChangesTree } from "../CommitView"; +import { useChangelists } from "../changelists"; +import { useCommit } from "../commitStore"; +import { useVcs } from "../store"; + +const change = (path: string, unstaged: "modified" | "untracked" = "modified") => ({ + path, + relPath: path.replace(/^\/p\//, ""), + staged: null, + unstaged, + renamedFrom: null, +}); + +const status = [change("/p/a.ts"), change("/p/b.ts"), change("/p/c.ts"), change("/p/new.txt", "untracked")]; + +// The active list was created last; the default list keeps its id but is not active. +const lists: ChangelistState = { + lists: [ + { id: "default", name: "Default Changelist", comment: "" }, + { id: "skip", name: "不提交", comment: "" }, + { id: "list10", name: "Task 10", comment: "" }, + { id: "list9", name: "task 9", comment: "" }, + { id: "work", name: "更改", comment: "" }, + ], + active: "work", + files: { "a.ts": "default", "b.ts": "skip", "c.ts": "work" }, +}; + +const groupLabels = (nodes: ReturnType) => nodes.map((n) => n.label); + +describe("the active changelist", () => { + it("comes first, the other lists follow by name, Unversioned Files last", () => { + expect(groupLabels(buildChangeTree(status, "/p", false, lists))).toEqual([ + "更改", + "Default Changelist", + "task 9", + "Task 10", + "不提交", + "Unversioned Files", + ]); + }); + + describe("in the Commit tool window", () => { + beforeEach(() => { + localStorage.clear(); + useCommit.setState({ groupByDir: false, checks: new Map(), selection: [] }); + useChangelists.setState({ state: lists }); + useVcs.setState({ root: "/p", repo: "/p", roots: ["/p"], heads: {}, status }); + }); + + it("is the only list drawn bold", () => { + render(); + const bold = (name: string) => screen.getByText(name, { exact: true }).className.includes("activeList"); + expect(bold("更改")).toBe(true); + for (const name of ["Default Changelist", "不提交", "task 9", "Task 10", "Unversioned Files"]) { + expect(bold(name), name).toBe(false); + } + }); + }); +}); diff --git a/src/features/vcs/changes.ts b/src/features/vcs/changes.ts index 10d40b2217..fda279e5b5 100644 --- a/src/features/vcs/changes.ts +++ b/src/features/vcs/changes.ts @@ -420,7 +420,13 @@ export function buildChangeTree( const id = groupOf(f) === "unversioned" ? lists.active : lists.files?.[relTo(root, stripSlash(f.path))]; byList.get(id && byList.has(id) ? id : lists.active)?.push(f); } - for (const l of lists.lists) { + // The active list first, the others by name, as IDEA sorts them (ChangesBrowserChangeListNode). + const ordered = [...lists.lists].sort( + (a, b) => + Number(b.id === lists.active) - Number(a.id === lists.active) || + a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: "base" }), + ); + for (const l of ordered) { const own = byList.get(l.id) ?? []; // Empty lists are shown once the user has more than the default one. if (!own.length && lists.lists.length < 2) continue;