From 63c2ced086d0f11283df7232b549c498e77a32e7 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 1 Dec 2026 12:06:34 -0300 Subject: [PATCH] fix(vcs): focus the diff's text when the modal diff window opens (#7252) Under the modal commit interface the diff window gave initial focus to its toolbar's first button, so F7 / Shift+F7 did nothing until a click in the text. The dialog body is now the autofocus target and an editor focus host, handing focus to the diff's text. Closes #7250 Co-authored-by: formiat <29867335+formiat@users.noreply.github.com> --- e2e/gitLogToolbarMenus.spec.ts | 28 ++++++++++++++++++++++++++++ src/features/vcs/diffDialog.tsx | 5 +++++ 2 files changed, 33 insertions(+) diff --git a/e2e/gitLogToolbarMenus.spec.ts b/e2e/gitLogToolbarMenus.spec.ts index 0ef16aee64..da46c3c430 100644 --- a/e2e/gitLogToolbarMenus.spec.ts +++ b/e2e/gitLogToolbarMenus.spec.ts @@ -523,6 +523,34 @@ test("Git Log file selection stays in place and opens a diff on activation", asy await expect(firstDiff).toHaveAttribute("aria-selected", "true"); }); +test("a Git Log file's diff window under the modal commit interface takes focus: F7 works at once", async ({ + workbench: page, +}) => { + await page.evaluate(async () => { + const h = window.__ipc.handlers; + h.vcs_commit_files = () => [{ path: "src/orders.ts", kind: "modified", oldPath: null }]; + // Two differences far apart, so F7 has somewhere to go. + h.vcs_file_at = ({ rev }) => { + const lines = Array.from({ length: 80 }, (_, i) => `const step${i} = ${i};`); + if (rev === "0".repeat(40)) for (const i of [5, 60]) lines[i] = `const step${i} = ${i} * 2;`; + return `${lines.join("\n")}\n`; + }; + const projectModule = "/src/platform/project.ts"; + const { useProject } = await import(/* @vite-ignore */ projectModule); + const settings = structuredClone(useProject.getState().settings ?? {}) as Record>; + settings.vcs = { ...settings.vcs, commit: { ...(settings.vcs?.commit as object), nonModal: false } }; + useProject.setState({ settings: settings as never }); + }); + await page.getByRole("listbox", { name: "Commits" }).getByRole("option").first().click(); + await page.getByRole("tree", { name: "Changed files" }).getByRole("treeitem", { name: "orders.ts" }).dblclick(); + const dialog = page.getByRole("dialog", { name: /^orders\.ts/ }); + await expect(dialog.getByText("1 of 2 differences", { exact: true })).toBeVisible(); + // The diff's text has focus, not the toolbar's first button. + await expect(dialog.locator(".cm-editor.cm-focused")).toHaveCount(1); + await page.keyboard.press("F7"); + await expect(dialog.getByText("2 of 2 differences", { exact: true })).toBeVisible(); +}); + test("Not Cherry-Picked Commits dims other rows while keeping unpicked commits readable", async ({ workbench: page, }) => { diff --git a/src/features/vcs/diffDialog.tsx b/src/features/vcs/diffDialog.tsx index 45d6601f07..edbf52461c 100644 --- a/src/features/vcs/diffDialog.tsx +++ b/src/features/vcs/diffDialog.tsx @@ -118,6 +118,11 @@ export function DiffDialogFrame({