From 31ca9daa61abddf90b9357144aa9f8a7e8e8a0bd Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sat, 21 Nov 2026 11:57:07 +0800 Subject: [PATCH] fix(vcs): align the target changelist dialog (#4947) Put existing and new target changelists in one editable **Name** field. Open the list to pick an existing target or enter a name to make a new one. The comment and active status sit in the same place for both choices. Undo Commit offers the commit subject as a suggested name. --- e2e/changelistFormLayout.spec.ts | 43 ++++- src/features/vcs/ChangelistForm.module.css | 36 +++++ src/features/vcs/changelistsUi.tsx | 173 +++++++++++++++------ src/platform/locales/text/en.json | 1 + src/platform/locales/text/es.json | 3 - src/platform/locales/text/fr.json | 3 - src/platform/locales/text/ko.json | 3 - src/platform/locales/text/pl.json | 3 - src/platform/locales/text/pt.json | 3 - src/platform/locales/text/tr.json | 3 - src/platform/locales/text/zh.json | 4 +- 11 files changed, 200 insertions(+), 75 deletions(-) diff --git a/e2e/changelistFormLayout.spec.ts b/e2e/changelistFormLayout.spec.ts index 483db03ea..ec6029ca0 100644 --- a/e2e/changelistFormLayout.spec.ts +++ b/e2e/changelistFormLayout.spec.ts @@ -37,7 +37,15 @@ test("changelist forms align the fields and preserve multiline comments through const listModule = "/src/features/vcs/changelists.ts"; const { initialChangelists, useChangelists } = await import(/* @vite-ignore */ listModule); useChangelists.setState({ - state: { ...initialChangelists(), files: { "build.gradle.kts": "default" } }, + state: { + ...initialChangelists(), + lists: [ + ...initialChangelists().lists, + { id: "inbox", name: "Review inbox", comment: "Choose a reviewer before merging." }, + { id: "unsorted", name: "Unsorted" }, + ], + files: { "build.gradle.kts": "default" }, + }, loaded: true, }); window.__ipc.handlers.vcs_changelists_save = () => null; @@ -94,16 +102,41 @@ test("changelist forms align the fields and preserve multiline comments through await action(page, "vcs.changelist.move", ["/dev/acme-api/build.gradle.kts"]); const move = page.getByRole("dialog", { name: "Move Changes to Another Changelist" }); - await move.getByRole("radio", { name: "New changelist:" }).check(); - await page.setViewportSize({ width: 400, height: 540 }); const newName = move.getByRole("textbox", { name: "Name:", exact: true }); + const targetComment = move.getByRole("textbox", { name: "Comment:", exact: true }); + const moveOk = move.getByRole("button", { name: "OK", exact: true }); + await expect(newName).toBeFocused(); + await expect(newName).toHaveValue("Release review"); + await expect(targetComment).toHaveAttribute("readonly", ""); + await newName.press("ArrowDown"); + const options = page.getByRole("listbox", { name: "Target changelist" }); + await expect(options).toBeVisible(); + await page.keyboard.press("Escape"); + await expect(options).toBeHidden(); + await expect(newName).toBeFocused(); + await newName.press("ArrowDown"); + await expect(options.getByRole("option", { name: "Changes", exact: true })).toHaveCount(0); + await options.getByRole("option", { name: "Review inbox", exact: true }).click(); + await expect(newName).toHaveValue("Review inbox"); + await expect(targetComment).toHaveValue("Choose a reviewer before merging."); + await newName.fill("Changes"); + await expect(newName).toHaveAccessibleDescription(/already exists/); + await expect(moveOk).toBeDisabled(); + + await page.setViewportSize({ width: 400, height: 540 }); const stackedName = (await newName.boundingBox())!; const stackedLabel = (await move.getByText("Name:", { exact: true }).boundingBox())!; expect(stackedLabel.y + stackedLabel.height).toBeLessThanOrEqual(stackedName.y); expect(Math.abs(stackedLabel.x - stackedName.x)).toBeLessThan(1); await newName.fill("Ready to ship"); - await move.getByRole("textbox", { name: "Comment:", exact: true }).fill("Move the reviewed change here."); - await move.getByRole("button", { name: "OK", exact: true }).click(); + await expect(targetComment).toBeEditable(); + await targetComment.fill("Move the reviewed change here."); + await newName.fill("Unsorted"); + await expect(targetComment).toHaveAttribute("readonly", ""); + await expect(targetComment).toHaveValue(""); + await newName.fill("Ready to ship"); + await expect(targetComment).toHaveValue("Move the reviewed change here."); + await moveOk.click(); await expect .poll(async () => { const state = await savedLists(page); diff --git a/src/features/vcs/ChangelistForm.module.css b/src/features/vcs/ChangelistForm.module.css index 583bb18c4..b41aa3faa 100644 --- a/src/features/vcs/ChangelistForm.module.css +++ b/src/features/vcs/ChangelistForm.module.css @@ -26,9 +26,45 @@ gap: var(--space-1); min-width: 0; } +.hint { + grid-column: 1 / -1; + color: var(--fg-subtle); +} +.picker { + display: flex; + align-items: center; + gap: var(--space-1); + min-width: 0; + padding-inline-end: var(--space-1); + border-radius: var(--radius-control); + background: var(--bg-field, var(--bg-button)); + box-shadow: inset 0 0 0 1px var(--border-button); +} +.picker:focus-within, +.picker[data-open] { + box-shadow: + inset 0 0 0 1px var(--focus-ring), + 0 0 0 1px var(--focus-ring); +} +.picker[data-invalid] { + box-shadow: + inset 0 0 0 1px var(--danger), + 0 0 0 1px var(--danger); +} +.picker > input { + flex: 1; + padding-inline-start: var(--space-2); +} +.newName { + color: var(--vcs-added); + font-size: var(--fs-small); +} .form > textarea { min-width: 0; } +.form > textarea[readonly] { + color: var(--fg-secondary); +} .active { grid-column: 1 / -1; justify-self: start; diff --git a/src/features/vcs/changelistsUi.tsx b/src/features/vcs/changelistsUi.tsx index d76b69bd2..2d6423f97 100644 --- a/src/features/vcs/changelistsUi.tsx +++ b/src/features/vcs/changelistsUi.tsx @@ -1,6 +1,7 @@ /** Change list dialogs: New / Edit Changelist, Move to Another Changelist, delete. */ -import { useId, useState } from "react"; -import { Checkbox, Dialog, Input, Select, T } from "@/ui"; +import { useId, useRef, useState, type ChangeEvent } from "react"; +import { Checkbox, Dialog, IconButton, Input, Popup, SelectListbox, T, type SelectOption } from "@/ui"; +import type { InputProps } from "@/ui/Input"; import { notifications } from "@/workbench/contributions"; import { activeList, @@ -32,33 +33,116 @@ interface FormValue { active: boolean; } +function ChangelistNamePicker({ + field, + options, + newName, + onChoose, +}: { + field: InputProps; + options: readonly SelectOption[]; + newName: boolean; + onChoose: (name: string) => void; +}) { + const anchor = useRef(null); + const input = useRef(null); + const [open, setOpen] = useState(false); + return ( + <> +
+ { + if (event.key !== "ArrowDown" || event.nativeEvent.isComposing || !options.length) return; + event.preventDefault(); + setOpen(true); + }} + /> + {newName && ( + + New + + )} + { + input.current?.focus(); + setOpen(!open); + }} + /> +
+ setOpen(false)} anchor={anchor} matchWidth role="presentation"> + { + onChoose(name); + setOpen(false); + }} + /> + + + ); +} + function ChangelistForm({ value, onChange, error, activeDisabled, + nameOptions, + existingDetails, + hint, }: { value: FormValue; onChange: (v: FormValue) => void; error: string | null; activeDisabled?: boolean; + nameOptions?: readonly SelectOption[]; + existingDetails?: Pick; + hint?: string; }) { const id = useId(); const errorId = value.name && error ? `${id}-error` : undefined; + const nameField = { + id: `${id}-name`, + "data-autofocus": "", + value: value.name, + invalid: !!errorId, + "aria-describedby": errorId, + onChange: (e: ChangeEvent) => onChange({ ...value, name: e.target.value }), + }; return (
+ {hint &&
{hint}
}
- onChange({ ...value, name: e.target.value })} - /> + {nameOptions ? ( + onChange({ ...value, name })} + /> + ) : ( + + )} {errorId && (
{error} @@ -72,13 +156,14 @@ function ChangelistForm({ id={`${id}-comment`} className={styles.textarea} rows={4} - value={value.comment} + value={existingDetails?.comment ?? value.comment} + readOnly={!!existingDetails} onChange={(e) => onChange({ ...value, comment: e.target.value })} /> onChange({ ...value, active })} label="Set active" /> @@ -299,13 +384,26 @@ function TargetListDialog({ const state = useChangelists((s) => s.state); const [currentLists] = useState(() => new Set(exclude)); const others = state.lists.filter((l) => !(currentLists.size === 1 && currentLists.has(l.id))); - const [mode, setMode] = useState<"existing" | "new">(others.length ? "existing" : "new"); - const [target, setTarget] = useState((others.find((l) => l.id === state.active) ?? others[0])?.id ?? state.active); - const [value, setValue] = useState({ name: suggestedName, comment: "", active: false }); - const error = mode === "new" ? validateListName(state, value.name) : null; + const [value, setValue] = useState(() => ({ + name: (others.find((l) => l.id === state.active) ?? others[0])?.name ?? suggestedName, + comment: "", + active: false, + })); + const target = others.find((l) => l.name.toLowerCase() === value.name.trim().toLowerCase()); + const error = target ? null : validateListName(state, value.name); + const nameOptions: SelectOption[] = others.map((l) => ({ + value: l.name, + label: l.id === state.active ? tx`${l.name} (active)` : l.name, + verbatim: true, + })); + if (!validateListName(state, suggestedName)) { + nameOptions.unshift({ value: suggestedName, label: suggestedName, detail: "New", verbatim: true }); + } const choose = () => { if (error) return; - if (mode === "new") { + if (target) { + onChoose(target.id); + } else { let id = ""; updateChangelists((s) => { const r = addList(s, value.name, { comment: value.comment, makeActive: value.active }); @@ -313,8 +411,6 @@ function TargetListDialog({ return r.state; }); onChoose(id); - } else { - onChoose(target); } onClose(); }; @@ -329,35 +425,14 @@ function TargetListDialog({ { label: "Cancel", role: "cancel" }, ]} > -
- {hint &&
{hint}
} - - setMode("new")} /> - - New changelist: - - -
- {mode === "new" && } + ); } diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 4aef7b7b7..910b27522 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -1539,6 +1539,7 @@ "Show Incoming and Outgoing Commits": "Show Incoming and Outgoing Commits", "Open in Git Log": "Open in Git Log", "Could not show diff": "Could not show diff", + "Choose changelist": "Choose changelist", "Comparison actions": "Comparison actions", "This branch has no upstream. Push it to compare with a remote branch.": "This branch has no upstream. Push it to compare with a remote branch.", "Highlight occurrences of selected text": "Highlight occurrences of selected text", diff --git a/src/platform/locales/text/es.json b/src/platform/locales/text/es.json index ae215100b..c803d07b8 100644 --- a/src/platform/locales/text/es.json +++ b/src/platform/locales/text/es.json @@ -797,8 +797,6 @@ "Execute Maven Goal…": "Ejecutar objetivo de Maven…", "Execute SQL Statement": "Ejecutar instrucción SQL", "Execute a statement in a query console with ⌘↩.": "Ejecuta una instrucción en una consola de consultas con ⌘↩.", - "Existing changelist": "Lista de cambios existente", - "Existing changelist:": "Lista de cambios existente:", "Existing environment": "Entorno existente", "Exit": "Salir", "Expand": "Expandir", @@ -1284,7 +1282,6 @@ "New Tag…": "Nueva etiqueta…", "New Terminal Tab": "Nueva pestaña de terminal", "New branch name:": "Nombre de la nueva rama:", - "New changelist:": "Nueva lista de cambios:", "New environment": "Nuevo entorno", "New file from template": "Nuevo archivo desde plantilla", "New from Template…": "Nuevo desde plantilla…", diff --git a/src/platform/locales/text/fr.json b/src/platform/locales/text/fr.json index bf8c9f6a3..d324251b7 100644 --- a/src/platform/locales/text/fr.json +++ b/src/platform/locales/text/fr.json @@ -734,8 +734,6 @@ "Execute Maven Goal…": "Exécuter un goal Maven…", "Execute SQL Statement": "Exécuter l'instruction SQL", "Execute a statement in a query console with ⌘↩.": "Exécutez une instruction dans une console de requêtes avec ⌘↩.", - "Existing changelist": "Liste de modifications existante", - "Existing changelist:": "Liste de modifications existante :", "Existing environment": "Environnement existant", "Exit": "Quitter", "Expand": "Développer", @@ -1219,7 +1217,6 @@ "New Tag…": "Nouveau tag…", "New Terminal Tab": "Nouvel onglet de terminal", "New branch name:": "Nom de la nouvelle branche :", - "New changelist:": "Nouvelle liste de modifications :", "New environment": "Nouvel environnement", "New file from template": "Nouveau fichier depuis un modèle", "New from Template…": "Nouveau depuis un modèle…", diff --git a/src/platform/locales/text/ko.json b/src/platform/locales/text/ko.json index 92d583e46..3d4f5c29a 100644 --- a/src/platform/locales/text/ko.json +++ b/src/platform/locales/text/ko.json @@ -833,8 +833,6 @@ "Execute Maven Goal…": "Maven 목표 실행…", "Execute SQL Statement": "SQL 문 실행", "Execute a statement in a query console with ⌘↩.": "쿼리 콘솔에서 ⌘↩로 문을 실행하세요.", - "Existing changelist": "기존 변경 목록", - "Existing changelist:": "기존 변경 목록:", "Existing environment": "기존 환경", "Exit": "종료", "Expand": "펼치기", @@ -1320,7 +1318,6 @@ "New Tag…": "새 태그…", "New Terminal Tab": "새 터미널 탭", "New branch name:": "새 브랜치 이름:", - "New changelist:": "새 변경 목록:", "New environment": "새 환경", "New file from template": "템플릿에서 새 파일", "New from Template…": "템플릿에서 새로 만들기…", diff --git a/src/platform/locales/text/pl.json b/src/platform/locales/text/pl.json index fe18004ec..355b3846d 100644 --- a/src/platform/locales/text/pl.json +++ b/src/platform/locales/text/pl.json @@ -789,8 +789,6 @@ "Execute Maven Goal…": "Wykonaj cel (goal) Maven…", "Execute SQL Statement": "Wykonaj instrukcję SQL", "Execute a statement in a query console with ⌘↩.": "Wykonaj instrukcję w konsoli zapytań za pomocą ⌘↩.", - "Existing changelist": "Istniejąca lista zmian", - "Existing changelist:": "Istniejąca lista zmian:", "Existing environment": "Istniejące środowisko", "Exit": "Wyjście", "Expand": "Rozwiń", @@ -1274,7 +1272,6 @@ "New Tag…": "Nowy tag…", "New Terminal Tab": "Nowa karta terminala", "New branch name:": "Nazwa nowej gałęzi:", - "New changelist:": "Nowa lista zmian:", "New environment": "Nowe środowisko", "New file from template": "Nowy plik z szablonu", "New from Template…": "Nowy z szablonu…", diff --git a/src/platform/locales/text/pt.json b/src/platform/locales/text/pt.json index 3d26da1a2..fbd0eb5e0 100644 --- a/src/platform/locales/text/pt.json +++ b/src/platform/locales/text/pt.json @@ -789,8 +789,6 @@ "Execute Maven Goal…": "Executar goal do Maven…", "Execute SQL Statement": "Executar instrução SQL", "Execute a statement in a query console with ⌘↩.": "Execute uma instrução em um console de consulta com ⌘↩.", - "Existing changelist": "Lista de alterações existente", - "Existing changelist:": "Lista de alterações existente:", "Existing environment": "Ambiente existente", "Exit": "Sair", "Expand": "Expandir", @@ -1274,7 +1272,6 @@ "New Tag…": "Nova tag…", "New Terminal Tab": "Nova aba do terminal", "New branch name:": "Nome da nova branch:", - "New changelist:": "Nova lista de alterações:", "New environment": "Novo ambiente", "New file from template": "Novo arquivo a partir de modelo", "New from Template…": "Novo a partir de modelo…", diff --git a/src/platform/locales/text/tr.json b/src/platform/locales/text/tr.json index 6b493f710..08abc3d0b 100644 --- a/src/platform/locales/text/tr.json +++ b/src/platform/locales/text/tr.json @@ -3589,8 +3589,6 @@ "Execute Maven Goal…": "Maven Hedefini Yürüt…", "Execute SQL Statement": "SQL İfadesini Yürüt", "Execute a statement in a query console with ⌘↩.": "Sorgu konsolunda ⌘↩ ile bir SQL ifadesi yürütün.", - "Existing changelist": "Mevcut değişiklik listesi", - "Existing changelist:": "Mevcut değişiklik listesi:", "Existing environment": "Mevcut ortam", "Exit": "Çıkış", "Expand": "Genişlet", @@ -4058,7 +4056,6 @@ "New Tag…": "Yeni Etiket…", "New Terminal Tab": "Yeni Terminal Sekmesi", "New branch name:": "Yeni dal adı:", - "New changelist:": "Yeni değişiklik listesi:", "New environment": "Yeni ortam", "New file from template": "Şablondan yeni dosya", "New from Template…": "Şablondan Yeni…", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 55b1f5db6..b2744dc76 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -1456,8 +1456,6 @@ "Execute Maven Goal…": "执行 Maven 目标…", "Execute SQL Statement": "执行 SQL 语句", "Execute a statement in a query console with ⌘↩.": "在查询控制台中按 ⌘↩ 执行语句。", - "Existing changelist": "现有更改列表", - "Existing changelist:": "现有更改列表:", "Existing environment": "现有环境", "Exit": "退出", "Expand": "展开", @@ -1954,7 +1952,6 @@ "New Tag…": "新建标签…", "New Terminal Tab": "新建终端标签页", "New branch name:": "新分支名称:", - "New changelist:": "新更改列表:", "New environment": "新环境", "New file from template": "从模板新建文件", "New from Template…": "从模板新建…", @@ -3056,6 +3053,7 @@ "Tag value": "标签值", "Tags to push": "要推送的标签", "Target changelist": "目标更改列表", + "Choose changelist": "选择更改列表", "Target directory": "目标目录", "Teal": "蓝绿色", "Template body": "模板正文",