Skip to content

Commit 3e61886

Browse files
refactor(web): file browser records the right-click position on its own panel (#25908)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a4fe62e commit 3e61886

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,6 @@ export default function FileBrowserPanel({
173173

174174
// Shadow-DOM row rects are unreliable; capture the composed contextmenu event's viewport position.
175175
const contextMenuPointerRef = useRef<{ x: number; y: number; at: number } | null>(null);
176-
useEffect(() => {
177-
const capturePointer = (event: MouseEvent) => {
178-
contextMenuPointerRef.current = { x: event.clientX, y: event.clientY, at: event.timeStamp };
179-
};
180-
document.addEventListener("contextmenu", capturePointer, true);
181-
return () => document.removeEventListener("contextmenu", capturePointer, true);
182-
}, []);
183176

184177
const showEntryContextMenu = useStableCallback(
185178
(item: TreeContextMenuItem, context: TreeContextMenuOpenContext) => {
@@ -493,6 +486,10 @@ export default function FileBrowserPanel({
493486
ref={panelRef}
494487
className="flex min-h-0 flex-1 flex-col bg-background"
495488
data-file-browser-panel={`${environmentId}:${cwd}`}
489+
// Capture runs before the tree's shadow-internal row handler opens the menu.
490+
onContextMenuCapture={(event) => {
491+
contextMenuPointerRef.current = { x: event.clientX, y: event.clientY, at: event.timeStamp };
492+
}}
496493
>
497494
<div
498495
className="flex h-10 min-h-10 shrink-0 items-center gap-1 border-b border-border/60 bg-background px-2 in-data-[preview-panel-mode=inline]:mb-1 in-data-[preview-panel-mode=inline]:h-9 in-data-[preview-panel-mode=inline]:min-h-9 in-data-[preview-panel-mode=inline]:border-b-transparent"

0 commit comments

Comments
 (0)