Skip to content

Commit c5d1f86

Browse files
committed
fix(review): skip ToolbarHost mousemove when unfocused, drop type cast
Address PR review nits on #660: - ToolbarHost's window mousemove listener now bails on `!isFocused`, so dock-mounted-but-hidden panels don't track mouse for a toolbar the user can't see. Matches the intent of the existing isFocused prop already passed through to the hook for draft handling. - Widen useAnnotationToolbar's handleMouseMove arg to a structural `{clientX, clientY}` shape. The hook only reads those two fields, so accepting the structural shape eliminates the `as unknown as React.MouseEvent` cast in ToolbarHost while staying compatible with React.MouseEvent callers.
1 parent 8d6e71b commit c5d1f86

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

packages/review-editor/components/ToolbarHost.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,13 @@ export const ToolbarHost = forwardRef<ToolbarHostHandle, ToolbarHostProps>(funct
8787
// Replaces the parent's `onMouseMove={toolbar.handleMouseMove}` on its scroll
8888
// container — the hook only stashes clientX/Y for toolbar placement, so a
8989
// window-level listener is functionally equivalent for that purpose.
90+
// Skip when not focused so dock-mounted-but-hidden panels don't track.
9091
const handleMouseMove = toolbar.handleMouseMove;
9192
useEffect(() => {
92-
const onMove = (e: MouseEvent) => {
93-
handleMouseMove({ clientX: e.clientX, clientY: e.clientY } as unknown as React.MouseEvent);
94-
};
95-
window.addEventListener('mousemove', onMove);
96-
return () => window.removeEventListener('mousemove', onMove);
97-
}, [handleMouseMove]);
93+
if (!isFocused) return;
94+
window.addEventListener('mousemove', handleMouseMove);
95+
return () => window.removeEventListener('mousemove', handleMouseMove);
96+
}, [handleMouseMove, isFocused]);
9897

9998
useImperativeHandle(
10099
ref,

packages/review-editor/hooks/useAnnotationToolbar.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ export function useAnnotationToolbar({ patch, filePath, isFocused, onLineSelecti
133133
setDecorations([]);
134134
}, []);
135135

136-
// Track mouse position continuously for toolbar placement
137-
const handleMouseMove = useCallback((e: React.MouseEvent) => {
136+
// Track mouse position continuously for toolbar placement.
137+
// Accepts a structural shape so the same handler works for both React
138+
// synthetic events and native DOM MouseEvents (used by ToolbarHost).
139+
const handleMouseMove = useCallback((e: { clientX: number; clientY: number }) => {
138140
lastMousePosition.current = { x: e.clientX, y: e.clientY };
139141
}, []);
140142

0 commit comments

Comments
 (0)