fix(vcs): keep selection history in the editor Git menu (#5654)

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 <[email protected]>
Цей коміт міститься в:
faysouтаfaysou authored and GitHub committed 2026-11-25 02:17:58 +08:00
1 джерело fc4e4fa39a
коміт cd3399df60
5 files changed
+24 -13

No files matched your search

+13 -8
Переглянути файл
@@ -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();
});
+1 -1
Переглянути файл
@@ -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");
+3 -2
Переглянути файл
@@ -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",
+4 -1
Переглянути файл
@@ -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",
+3 -1
Переглянути файл
@@ -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…"),