From d78ce7ec6660cc0ba6b1995aaec31010cb00e81f Mon Sep 17 00:00:00 2001 From: Muu Date: Mon, 23 Nov 2026 21:10:34 +0800 Subject: [PATCH] fix(editor): offer contributed Copy Path links in the tab and library menus (#5400) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copy Path/Reference… built a different submenu per entry point: the project view and the editor caret chooser list the contributed copy items (features/vcs: Path From Repository Root, GitHub Link), while the editor tab menu and the External Libraries menu hand-wrote theirs and silently dropped every contribution. Both hand-written submenus now append the same `copyPath` menu group, so all four entry points agree — and future contributions appear everywhere at once. Co-authored-by: muutot <92625353+muutot@users.noreply.github.com> --- src/editor/core/controller.test.ts | 41 +++++++++++++++++++ src/editor/core/controller.ts | 3 ++ src/features/project-tree/contextMenu.test.ts | 16 ++++++++ src/features/project-tree/contextMenu.ts | 2 + 4 files changed, 62 insertions(+) diff --git a/src/editor/core/controller.test.ts b/src/editor/core/controller.test.ts index 799c1370d..997a528db 100644 --- a/src/editor/core/controller.test.ts +++ b/src/editor/core/controller.test.ts @@ -8,6 +8,7 @@ import { resetDistractionFree, setDistractionFree } from "@/workbench/distractio import * as contributions from "@/workbench/contributions"; import { registerEditorKind, + registerMenuGroup, registerTextEditorWrapper, setProjectViewLead, useProjectViewLead, @@ -579,6 +580,46 @@ describe("EditorController", () => { useProject.setState({ project: null, settings: null }); }); + it("offers contributed Copy Path links in the tab menu like the other copy menus", async () => { + useProject.setState({ + project: { name: "p", root: "/p", trusted: true, isGit: true, settings: {} } as never, + settings: {} as never, + }); + const dispose = registerActions( + ["project.copyAbsolutePath", "project.copyFileName", "project.copyRelativePath"].map((id) => ({ + id, + title: id, + run: () => undefined, + })), + ); + const links = registerMenuGroup({ + id: "test.link", + menus: ["copyPath"], + items: () => [{ id: "test.copyLink", label: "GitHub Link", verbatim: true, run: () => undefined }], + }); + try { + ctrl = new EditorController(createMemoryBackend({ "/p/a.ts": "" })); + ctrl.start(); + await ctrl.openFile("/p/a.ts", { focus: false }); + const s = useTabs.getState(); + const pane = s.panes[s.activePane]!; + const submenu = resolveMenuItems(ctrl.tabMenu(pane.id, pane.tabs[0]!)).find( + (i) => i.label === "Copy Path/Reference…", + )!.submenu!; + expect(resolveMenuItems(submenu).map((i) => (i.kind === "separator" ? "-" : i.label))).toEqual([ + "Absolute Path", + "File Name", + "Path From Content Root", + "-", + "GitHub Link", + ]); + } finally { + dispose(); + links(); + useProject.setState({ project: null, settings: null }); + } + }); + it.each(["editor", "tab"])( "offers grouped Git actions in the %s menu and preserves action enablement", async (menu) => { diff --git a/src/editor/core/controller.ts b/src/editor/core/controller.ts index a301ffa52..97b830d3c 100644 --- a/src/editor/core/controller.ts +++ b/src/editor/core/controller.ts @@ -2324,6 +2324,9 @@ export class EditorController implements SlotHost { }, ] as MenuItem[]) : []), + // The links the project view and the editor chooser offer (features/vcs: GitHub Link). + { kind: "separator" }, + ...menuGroupItems("copyPath", { paths: [path] }), ], }, { kind: "separator" }, diff --git a/src/features/project-tree/contextMenu.test.ts b/src/features/project-tree/contextMenu.test.ts index 5ff93c85b..297619704 100644 --- a/src/features/project-tree/contextMenu.test.ts +++ b/src/features/project-tree/contextMenu.test.ts @@ -145,6 +145,22 @@ describe("project view context menu", () => { ]); }); + it("lists contributed links in Copy Path/Reference… of library files too", () => { + disposers.push( + registerMenuGroup({ + id: "test.link", + menus: ["copyPath"], + items: (_menu, ctx) => [{ label: `Link ${ctx.paths.join()}`, verbatim: true, run: () => undefined }], + }), + ); + expect(sub(contextMenuItems([{ ...node("/root/.m2/lib.jar"), readOnly: true }]), "Copy Path/Reference…")).toEqual([ + "Absolute Path", + "File Name", + "-", + "Link /root/.m2/lib.jar", + ]); + }); + it("groups clipboard, search, file changes, formatting and history actions for a file", () => { const items = contextMenuItems([node(`${ROOT}/src/a.py`)]); expect(labels(items)).toEqual([ diff --git a/src/features/project-tree/contextMenu.ts b/src/features/project-tree/contextMenu.ts index 32f93bf5d..8ddecaaf1 100644 --- a/src/features/project-tree/contextMenu.ts +++ b/src/features/project-tree/contextMenu.ts @@ -512,6 +512,8 @@ function libraryMenuItems(nodes: ProjectNode[]): MenuItem[] { run: () => void copyPaths("absolute", nodes), }, { id: "name", label: "File Name", run: () => void copyPaths("name", nodes) }, + { kind: "separator" }, + ...menuGroupItems("copyPath", menuGroupContext(nodes)), ], }, { kind: "separator" },