From cd3399df600ca7323928230318a9da053769113c Mon Sep 17 00:00:00 2001 From: faysou Date: Tue, 24 Nov 2026 18:17:58 +0000 Subject: [PATCH] fix(vcs): keep selection history in the editor Git menu (#5654) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The shared Git submenu (#5611) dropped Show History for Selection from the editor's context menu. It is back for a right-click in the editor and stays out of the tab and Project view menus. The browser tests now use the shared menu's labels and groups, including keyboard navigation to Get from Version Control…. Co-authored-by: faysou <893862+faysou@users.noreply.github.com> --- e2e/editorGitMenu.spec.ts | 21 +++++++++++++-------- e2e/menuLayout.spec.ts | 2 +- src/editor/core/controller.test.ts | 5 +++-- src/editor/core/controller.ts | 5 ++++- src/workbench/contributions.ts | 4 +++- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/e2e/editorGitMenu.spec.ts b/e2e/editorGitMenu.spec.ts index 1c2628ec95..ba468396b4 100644 --- a/e2e/editorGitMenu.spec.ts +++ b/e2e/editorGitMenu.spec.ts @@ -4,13 +4,16 @@ test("editor Git submenu offers the registered file and repository actions in gr const editor = await openFromTree(page, "README.md"); await editor.locator(".cm-content").click({ button: "right" }); await page.getByRole("menuitem", { name: "Git", exact: true }).hover(); - const git = page.getByRole("menu").filter({ has: page.getByRole("menuitem", { name: "Clone…", exact: true }) }); + const git = page + .getByRole("menu") + .filter({ has: page.getByRole("menuitem", { name: "Get from Version Control…", exact: true }) }); await expect(git.locator('[role="menuitem"], [role="menuitemcheckbox"]')).toHaveText([ /Commit File…/, - /Add/, + /^Add(?:⌥⌘A)?$/, + /Add to \.gitignore/, /Annotate with Git Blame/, /Show Diff/, - /Compare with Branch or Revision…/, + /Compare with Branch…/, /Compare with Revision…/, /Show History$/, /Show Current Revision/, @@ -29,7 +32,7 @@ test("editor Git submenu offers the registered file and repository actions in gr /Unstash Changes…/, /GitHub/, /Manage Remotes…/, - /Clone…/, + /Get from Version Control…/, ]); await expect(git.getByRole("separator")).toHaveCount(6); await git.getByRole("menuitem", { name: "GitHub", exact: true }).hover(); @@ -62,17 +65,19 @@ test("editor Git submenu keeps repository actions disabled without Git", async ( ]) { await expect(page.getByRole("menuitem", { name: new RegExp(`^${name}`) })).toBeDisabled(); } - await expect(page.getByRole("menuitem", { name: "Clone…", exact: true })).toBeEnabled(); + await expect(page.getByRole("menuitem", { name: "Get from Version Control…", exact: true })).toBeEnabled(); }); test("Project view Git submenu ends with Manage Remotes and Clone", async ({ workbench: page }) => { await page.getByRole("treeitem", { name: /README\.md/ }).click({ button: "right" }); await page.getByRole("menuitem", { name: "Git", exact: true }).hover(); - const git = page.getByRole("menu").filter({ has: page.getByRole("menuitem", { name: "Clone…", exact: true }) }); + const git = page + .getByRole("menu") + .filter({ has: page.getByRole("menuitem", { name: "Get from Version Control…", exact: true }) }); const items = git.locator('[role="menuitem"], [role="menuitemcheckbox"]'); - await expect(items.nth(-3)).toHaveText(/Unstash Changes…/); + await expect(items.nth(-3)).toHaveText(/GitHub/); await expect(items.nth(-2)).toHaveText(/Manage Remotes…/); - await expect(items.nth(-1)).toHaveText(/Clone…/); + await expect(items.nth(-1)).toHaveText(/Get from Version Control…/); await git.getByRole("menuitem", { name: "Manage Remotes…", exact: true }).click(); await expect(page.getByRole("dialog", { name: "Git Remotes" })).toBeVisible(); }); diff --git a/e2e/menuLayout.spec.ts b/e2e/menuLayout.spec.ts index 7bd39f82b9..0a139fde07 100644 --- a/e2e/menuLayout.spec.ts +++ b/e2e/menuLayout.spec.ts @@ -5,7 +5,7 @@ test("keyboard navigation reveals items in a short Git submenu", async ({ workbe const editor = await openFromTree(page, "README.md"); await editor.locator(".cm-content").click({ button: "right" }); await page.getByRole("menuitem", { name: "Git", exact: true }).hover(); - const last = page.getByRole("menuitem", { name: "Clone…", exact: true }); + const last = page.getByRole("menuitem", { name: "Get from Version Control…", exact: true }); const popup = last.locator("xpath=ancestor::*[@data-popup][1]"); const first = popup.locator('[role="menuitem"]:not([aria-disabled="true"])').first(); await expect(popup).toHaveAttribute("data-positioned", "true"); diff --git a/src/editor/core/controller.test.ts b/src/editor/core/controller.test.ts index 89d7155f90..533cb137f6 100644 --- a/src/editor/core/controller.test.ts +++ b/src/editor/core/controller.test.ts @@ -668,6 +668,7 @@ describe("EditorController", () => { "vcs.compareWithRevision", "vcs.showHistory", "vcs.showCurrentRevision", + ...(menu === "editor" ? ["vcs.showHistoryForSelection"] : []), "vcs.rollback", ], ["vcs.push", "vcs.pull", "vcs.fetch"], @@ -682,9 +683,9 @@ describe("EditorController", () => { "github.checkoutPullRequest", "github.openInBrowser", ]; - const ids = [...groups.flat().filter((id) => id !== "GitHub"), ...github]; + const ids = new Set([...groups.flat().filter((id) => id !== "GitHub"), ...github, "vcs.showHistoryForSelection"]); const dispose = registerActions( - ids.map((id) => ({ + [...ids].map((id) => ({ id, title: id, when: id === "vcs.clone" ? undefined : id.startsWith("github.") ? "projectOpen" : "vcsAvailable", diff --git a/src/editor/core/controller.ts b/src/editor/core/controller.ts index 5da38bd2d2..fcf798b5e9 100644 --- a/src/editor/core/controller.ts +++ b/src/editor/core/controller.ts @@ -1029,7 +1029,10 @@ export class EditorController implements SlotHost { openInMenu(slot.model.path, selectedLineContext(view.state)), { kind: "separator" }, localHistoryMenu(slot.model.path), - { label: "Git", submenu: gitMenuItems({ paths: [slot.model.path], file: true, ignore: true }) }, + { + label: "Git", + submenu: gitMenuItems({ paths: [slot.model.path], file: true, ignore: true, editorSelection: true }), + }, { kind: "separator" }, { kind: "action", diff --git a/src/workbench/contributions.ts b/src/workbench/contributions.ts index 3184b439a2..f108aac8d0 100644 --- a/src/workbench/contributions.ts +++ b/src/workbench/contributions.ts @@ -1542,6 +1542,7 @@ export interface GitMenuContext { file?: boolean; /** Show Add to .gitignore: the selection excludes the project root (which cannot be ignored). */ ignore?: boolean; + editorSelection?: boolean; } /** @@ -1549,7 +1550,7 @@ export interface GitMenuContext { * per-menu groups in sync). Items are plain action rows, so unregistered actions * disappear and `vcsAvailable` gates enablement on its own. */ -export function gitMenuItems({ paths, dirs, file, ignore }: GitMenuContext): MenuItem[] { +export function gitMenuItems({ paths, dirs, file, ignore, editorSelection }: GitMenuContext): MenuItem[] { const arg = paths.length === 1 ? paths[0]! : paths; const some = paths.length > 0; const single = paths.length === 1 ? paths[0]! : null; @@ -1579,6 +1580,7 @@ export function gitMenuItems({ paths, dirs, file, ignore }: GitMenuContext): Men ...(file ? ([act("vcs.compareWithRevision", "Compare with Revision…")] as (MenuItem | null)[]) : []), ...(some ? ([act("vcs.showHistory", "Show History")] as (MenuItem | null)[]) : []), ...(file ? ([act("vcs.showCurrentRevision", "Show Current Revision")] as (MenuItem | null)[]) : []), + ...(editorSelection ? [action("vcs.showHistoryForSelection", "Show History for Selection")] : []), act("vcs.rollback", "Rollback…"), { kind: "separator" }, action("vcs.push", "Push…"),