From c3196565295fb393d241956b95c7bf30ca429a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=8C?= <31638637+kitter960324@users.noreply.github.com> Date: Wed, 2 Dec 2026 14:51:05 +0800 Subject: [PATCH] feat(search): give every plugin search category its own action (#7405) Each plugin-contributed Search Everywhere category gets a Navigate action (Search Everywhere: ) that opens that tab, so a keymap can bind it directly. The actions follow the categories as plugins are enabled or disabled; no default shortcuts. Closes #7369 Co-authored-by: kitter960324 <31638637+kitter960324@users.noreply.github.com> --- .../__tests__/searchCategoryActions.test.ts | 49 +++++++++++++++++++ src/features/search/index.ts | 33 ++++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/features/search/__tests__/searchCategoryActions.test.ts diff --git a/src/features/search/__tests__/searchCategoryActions.test.ts b/src/features/search/__tests__/searchCategoryActions.test.ts new file mode 100644 index 0000000000..d5eba925eb --- /dev/null +++ b/src/features/search/__tests__/searchCategoryActions.test.ts @@ -0,0 +1,49 @@ +import { afterEach, beforeEach, describe, expect, it } from "vitest"; +import { executeAction, getAction } from "@/platform/actions"; +import { setContext } from "@/platform/context"; +import { registerSearchCategory } from "@/workbench/contributions"; +import { activate } from "../index"; +import { hideSearchEverywhere, useSearchEverywhere } from "../everywhere/store"; + +let dispose: (() => void) | void; + +beforeEach(() => { + dispose = activate(); + setContext("projectOpen", true); + hideSearchEverywhere(); +}); + +afterEach(() => { + dispose?.(); + setContext("projectOpen", false); +}); + +const category = (id: string, title: string) => ({ + id: id as `plugin:${string}:${string}`, + title, + search: async () => ({ items: [], hasMore: false }), + command: () => undefined, +}); + +describe("plugin search categories", () => { + it("opens its own Search Everywhere tab through an action named after the category", async () => { + const off = registerSearchCategory(category("plugin:acme:routes", "Routes")); + const id = "navigate.searchEverywhere.plugin.acme.routes"; + expect(getAction(id)?.title).toBe("Search Everywhere: Routes"); + await executeAction(id); + expect(useSearchEverywhere.getState()).toMatchObject({ open: true, tab: "plugin:acme:routes" }); + off(); + }); + + it("drops the action when the plugin's category goes away", () => { + const off = registerSearchCategory(category("plugin:acme:routes", "Routes")); + expect(getAction("navigate.searchEverywhere.plugin.acme.routes")).toBeDefined(); + off(); + expect(getAction("navigate.searchEverywhere.plugin.acme.routes")).toBeUndefined(); + }); + + it("keeps the built-in tabs' actions unchanged", () => { + expect(getAction("navigate.gotoFile")).toBeDefined(); + expect(getAction("navigate.searchEverywhere")).toBeDefined(); + }); +}); diff --git a/src/features/search/index.ts b/src/features/search/index.ts index 897a5c29b2..05da518414 100644 --- a/src/features/search/index.ts +++ b/src/features/search/index.ts @@ -14,7 +14,14 @@ import { isSameOrInside } from "@/platform/paths"; import { useProject } from "@/platform/project"; import { EDIT_SCOPES_ACTION } from "@/platform/search"; import { isVirtualUri } from "@/platform/virtualDocs"; -import { provideFindResults, registerMenuGroup, registerOverlay, registerToolWindow } from "@/workbench/contributions"; +import { + onSearchCategoriesChanged, + provideFindResults, + registerMenuGroup, + registerOverlay, + registerToolWindow, + searchCategories, +} from "@/workbench/contributions"; import { BookmarkPopupsOverlay } from "./bookmarks/BookmarkPopups"; import { bookmarkGutter } from "./bookmarks/gutter"; import { @@ -171,7 +178,30 @@ export function activate(): void | (() => void) { showSearchEverywhere(tab, { query: editorSelectionText() ?? undefined }); }; + // Each plugin's Search Everywhere category gets its own action: tabs follow the enabled + // plugins' order, so Tab-cycling to one is unreliable, while a keymap can name it directly. + // No default shortcut: the user binds one in Settings › Keymap. + let disposeCategoryActions: () => void = () => {}; + const registerCategoryActions = () => { + disposeCategoryActions(); + const categories = searchCategories(); + disposeCategoryActions = categories.length + ? registerActions( + categories.map((category) => ({ + id: `navigate.searchEverywhere.${category.id.replace(/[^A-Za-z0-9_.-]/g, ".")}`, + title: tx`Search Everywhere: ${category.title}`, + category: "Navigate" as const, + keywords: ["search everywhere", category.title], + when: "projectOpen", + run: se(category.id), + })), + ) + : () => {}; + }; + registerCategoryActions(); + const disposers: Array<() => void> = [ + onSearchCategoriesChanged(registerCategoryActions), installTracking(), provideFindResults(openEditorResults), @@ -625,6 +655,7 @@ export function activate(): void | (() => void) { return () => { closeAllPopups(); disposeFindWindow(); + disposeCategoryActions(); disposers.reverse().forEach((d) => d()); }; }