From b1039bc17587068ccb486bb3e236950310efcc49 Mon Sep 17 00:00:00 2001 From: Mollo-i <76565859+Greenker@users.noreply.github.com> Date: Mon, 30 Nov 2026 19:43:10 +0800 Subject: [PATCH] feat(search): select Search Everywhere results in the Project view (#6955) File, symbol and text results in Search Everywhere get Select in Project View, in the Alt+Enter menu and in a new right-click menu on the row: it closes the popup and selects the result in the Project tool window. This helps with files that open in another application, such as a .doc, where choosing the result leaves no trace of where the file lives. The item is offered only for paths inside the project. One item list now feeds both menus, and Open to the Side is disabled for folders. Co-authored-by: Greenker <76565859+Greenker@users.noreply.github.com> --- .../search/__tests__/dialogs.test.tsx | 34 +++++++++ .../search/everywhere/SearchEverywhere.tsx | 74 ++++++++++++++----- 2 files changed, 88 insertions(+), 20 deletions(-) diff --git a/src/features/search/__tests__/dialogs.test.tsx b/src/features/search/__tests__/dialogs.test.tsx index 8d9c1177db..3e33f819ff 100644 --- a/src/features/search/__tests__/dialogs.test.tsx +++ b/src/features/search/__tests__/dialogs.test.tsx @@ -62,6 +62,7 @@ vi.mock("../find/windowStore", async (orig) => ({ const contributions = await import("@/workbench/contributions"); const { commands, emitLocalIdeEvent } = await import("@/platform/ipc"); +const { ContextMenuHost } = await import("@/ui"); const { RecentPopupsOverlay } = await import("../recent/RecentPopups"); const { cycleSwitcher, showRecentPopup, hideRecentPopup, useRecentPopup } = await import("../recent/store"); const { openLocation } = await import("../common/open"); @@ -448,6 +449,39 @@ function clickOption(index: number, modifiers = {}) { fireEvent.click(row, modifiers); } +describe("Search Everywhere result actions", () => { + it.each(["keyboard", "right click"] as const)("selects a file in the Project view from the %s menu", async (how) => { + const run = vi.fn(); + const project = useProject.getState().project; + useProject.setState({ project: { root: "/p", name: "p", isGit: false } as never }); + const dispose = registerAction({ + id: "navigate.selectInProjectView", + title: "Select in Project View", + run: ({ arg }) => run(arg), + }); + try { + render( + <> + + + , + ); + act(() => showSearchEverywhere("files", { query: "order" })); + await tick(); + if (how === "keyboard") fireEvent.keyDown(screen.getByLabelText("Search query"), { key: "Enter", altKey: true }); + else fireEvent.contextMenu(resultOptions()[0]!); + await tick(); + fireEvent.click(screen.getByRole("menuitem", { name: /Select in Project View/ })); + await tick(); + expect(run).toHaveBeenCalledExactlyOnceWith("/p/src/OrderController.kt"); + expect(useSearchEverywhere.getState().open).toBe(false); + } finally { + dispose(); + useProject.setState({ project }); + } + }); +}); + describe("Search Everywhere multi-selection", () => { it("extends, shrinks, crosses the anchor and clamps Shift selection; plain arrows select one", async () => { const input = await showDuplicateFiles(); diff --git a/src/features/search/everywhere/SearchEverywhere.tsx b/src/features/search/everywhere/SearchEverywhere.tsx index a3bc86dcb2..b6fb476c35 100644 --- a/src/features/search/everywhere/SearchEverywhere.tsx +++ b/src/features/search/everywhere/SearchEverywhere.tsx @@ -34,13 +34,14 @@ import { selectRow, selectedRows, rowSelectionMode, + showContextMenu, type RowSelection, type MenuItem, T, } from "@/ui"; import { useFileDecoration } from "@/workbench/contributions"; import { highlightTokens, languageForPath, type CodeToken } from "@/editor/lsp/markdown"; -import { badgeKind, basename, openInListOrder, openLocation, relDir } from "../common/open"; +import { badgeKind, basename, openInListOrder, openLocation, projectRoot, relDir } from "../common/open"; import { parseLocationQuery } from "../common/query"; import { setTextSearchOption, useFindPopup } from "../find/store"; import { CodePreview, type PreviewHighlight } from "../find/parts"; @@ -441,35 +442,67 @@ function SearchEverywhereDialog() { /** IDEA's ⌥↵ on an action: record a shortcut for it (written to the active keymap). */ const assignShortcut = (id: string) => closeThen(() => void executeAction("settings.assignShortcut", id)); + /** Actions of a file, symbol or text result: IDEA's ⌥↵ menu and the row's context menu. */ + const resultMenu = (row: NavigationRow): MenuItem[] => { + const copy = (text: string) => void writeClipboardText(text).catch(() => {}); + const folder = row.kind === "file" && row.folder; + const root = projectRoot(); + const inProject = !!root && (row.path === root || row.path.startsWith(root.endsWith("/") ? root : `${root}/`)); + const items: MenuItem[] = [ + { label: "Open", run: () => activate(row) }, + { + label: "Open to the Side", + shortcut: formatBinding("Shift+Enter"), + disabled: !!folder, + run: () => activate(row, true), + }, + // IDEA's Select in Project View (Select Opened File): shows a result opened in another + // application (.doc in WPS) in the Project view, where its place in the project is visible. + ...(inProject + ? [ + { + label: "Select in Project View", + shortcut: shortcutLabel("navigate.selectInProjectView") ?? undefined, + run: () => closeThen(() => void executeActionFrom("search", "navigate.selectInProjectView", row.path)), + }, + ] + : []), + { kind: "separator" }, + ]; + items.push( + { label: "Copy Path", run: () => copy(nativePath(row.path)) }, + { label: "Copy Path from Project Root", run: () => copy(row.rel) }, + ...(row.kind === "symbol" ? [{ label: "Copy Name", run: () => copy(row.name) }] : []), + ...(row.kind === "file" || row.kind === "text" + ? [ + { + label: "Find in Directory…", + run: () => closeThen(() => void executeAction("find.inPath", { directory: dirOf(row.path) })), + }, + ] + : []), + ); + return items; + }; + const openIntentions = () => { const row = activeRow; if (!row || row.kind === "section" || row.kind === "more" || row.kind === "command") return; if (row.kind === "action") return row.run ? undefined : assignShortcut(row.id); const anchor = listRef.current?.querySelector('[data-lead="true"]') ?? inputRef.current; if (!anchor) return; - const copy = (text: string) => void writeClipboardText(text).catch(() => {}); const items: MenuItem[] = - row.kind === "setting" - ? [{ label: "Open Settings Page", run: () => activate(row) }] - : [ - { label: "Open", run: () => activate(row) }, - { label: "Open to the Side", shortcut: formatBinding("Shift+Enter"), run: () => activate(row, true) }, - { kind: "separator" }, - { label: "Copy Path", run: () => copy(nativePath(row.path)) }, - { label: "Copy Path from Project Root", run: () => copy(row.rel) }, - ...(row.kind === "symbol" ? [{ label: "Copy Name", run: () => copy(row.name) }] : []), - ...(row.kind === "file" || row.kind === "text" - ? [ - { - label: "Find in Directory…", - run: () => closeThen(() => void executeAction("find.inPath", { directory: dirOf(row.path) })), - }, - ] - : []), - ]; + row.kind === "setting" ? [{ label: "Open Settings Page", run: () => activate(row) }] : resultMenu(row); setMenu({ anchor, items, placement: "right-start" }); }; + const onRowContextMenu = (row: SeRow, index: number, e: MouseEvent) => { + if (row.kind !== "file" && row.kind !== "symbol" && row.kind !== "text") return; + e.preventDefault(); + select(index, e); + showContextMenu(e, resultMenu(row)); + }; + const onKeyDown = (e: KeyboardEvent) => { if (isImeKey(e.nativeEvent)) return; if (tab === "text" && e.altKey && !e.metaKey && !e.ctrlKey && !e.shiftKey) { @@ -574,6 +607,7 @@ function SearchEverywhereDialog() { if (preview && previewOf(r) && e.type === "click" && e.detail !== 2) return; activate(r, e.shiftKey); }} + onContextMenu={onRowContextMenu} focusable={false} rowHeight={rowHeight} sectionHeight={rowHeight}