дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
feat(search): give every plugin search category its own action (#7405)
Each plugin-contributed Search Everywhere category gets a Navigate action (Search Everywhere: <category>) 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 <[email protected]>
Цей коміт міститься в:
2 files changed
+81
-1
No files matched your search
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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());
|
||||
};
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача