Skip to content

Commit bf0d09a

Browse files
author
Dan Bolser
committed
fix(web): file context menu actions respond to pointer clicks
1 parent d07c0a7 commit bf0d09a

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎apps/web/src/components/files/FileBrowserPanel.browser.test.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { EnvironmentId, type ProjectEntry } from "@t3tools/contracts";
22
import { describe, expect, it, vi } from "vite-plus/test";
3+
import { page, userEvent } from "vite-plus/test/browser";
34

45
import { COMPOSER_MENTION_DRAG_TYPE } from "~/components/chat/composerMentionDrag";
6+
import { dismissContextMenu } from "~/contextMenuFallback";
57
import { render } from "../../../test/render";
68
import FileBrowserPanel from "./FileBrowserPanel";
79

@@ -43,6 +45,35 @@ function findTreeRow(path: string): HTMLElement | null {
4345
}
4446

4547
describe("FileBrowserPanel", () => {
48+
it("Copy mention reaches the clipboard when clicked with the pointer", async () => {
49+
await using _screen = await render(
50+
<FileBrowserPanel
51+
environmentId={EnvironmentId.make("env-files")}
52+
cwd="/repo"
53+
projectName="repo"
54+
selectedPath={null}
55+
selectedPathRevealId={0}
56+
onOpenFile={() => {}}
57+
workspaceMutationId={null}
58+
/>,
59+
);
60+
using _menu = { [Symbol.dispose]: () => dismissContextMenu() };
61+
using clipboard = vi.spyOn(navigator.clipboard, "writeText").mockResolvedValue(undefined);
62+
await vi.waitFor(() => expect(findTreeRow("README.md")).not.toBeNull());
63+
findTreeRow("README.md")!.dispatchEvent(
64+
new MouseEvent("contextmenu", {
65+
bubbles: true,
66+
cancelable: true,
67+
composed: true,
68+
button: 2,
69+
}),
70+
);
71+
const action = page.getByRole("menuitem", { name: "Copy mention", exact: true });
72+
await expect.element(action).toBeVisible();
73+
await userEvent.click(action);
74+
await vi.waitFor(() => expect(clipboard).toHaveBeenCalledWith("[README.md](README.md)"));
75+
});
76+
4677
it("dragging a file row carries a composer mention without opening it, and dragend releases it", async () => {
4778
const onOpenFile = vi.fn();
4879
await using _screen = await render(

‎apps/web/src/components/files/FileBrowserPanel.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ export default function FileBrowserPanel({
192192
: { x: anchorRect.left, y: anchorRect.bottom };
193193
const fileTarget = { environmentId, filePath: relativePath, workspaceRoot: cwd };
194194
const fileMenuItems = fileContextMenu.buildItems(fileTarget);
195+
// The app menu owns focus; the tree's outside-click handler would dismiss it before click.
196+
context.close({ restoreFocus: false });
195197
void settlePromise(async () => {
196198
const clicked = await api.contextMenu.show(
197199
[
@@ -246,7 +248,6 @@ export default function FileBrowserPanel({
246248
}
247249
}
248250
}).then((result) => {
249-
context.close();
250251
if (!AsyncResult.isSuccess(result)) throw Cause.squash(result.cause);
251252
});
252253
},

0 commit comments

Comments
 (0)