From 3b20e07b17d0e8b490852fd528a99c1ff70a1c5e Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Mon, 11 Aug 2025 19:32:20 +0200 Subject: [PATCH] fix(RegionMap.tsx): restrict map interactions to left mouse button for consistency --- frontend/src/components/RegionMap.tsx | 37 +++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/RegionMap.tsx b/frontend/src/components/RegionMap.tsx index 81ecc1e..c31ce70 100644 --- a/frontend/src/components/RegionMap.tsx +++ b/frontend/src/components/RegionMap.tsx @@ -119,6 +119,7 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho const [indicatedSystem, setIndicatedSystem] = useState(null); const selectTimerRef = useRef(null); const downClientPointRef = useRef<{ x: number; y: number } | null>(null); + const mouseButtonRef = useRef(null); // New: shift-drag circle selection state (VIA mode) const [shiftSelecting, setShiftSelecting] = useState(false); @@ -534,8 +535,10 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho const handleMouseDown = useCallback((e: React.MouseEvent) => { if (!svgRef.current) return; - // SHIFT + VIA mode: start circle selection - if (viaMode && e.shiftKey) { + mouseButtonRef.current = e.button; + + // SHIFT + VIA mode: start circle selection (left button only) + if (viaMode && e.shiftKey && e.button === 0) { e.preventDefault(); e.stopPropagation(); const svgPt = clientToSvg(e.clientX, e.clientY); @@ -550,6 +553,13 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho return; } + // Only left button initiates selection/panning + if (e.button !== 0) { + clearSelectTimer(); + setIsSelecting(false); + return; + } + // record down point (client) and seed pan origin const rect = svgRef.current.getBoundingClientRect(); setLastPanPoint({ x: e.clientX - rect.left, y: e.clientY - rect.top }); @@ -625,9 +635,11 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho // if dragging node, delegate if (draggingNode) { if (e) handleSvgMouseUp(e); return; } - // Commit shift selection if active + // Commit shift selection if active (only if left button initiated) if (shiftSelecting) { - commitShiftSelection(); + if (mouseButtonRef.current === 0) { + commitShiftSelection(); + } setShiftSelecting(false); setShiftCenter(null); setShiftRadius(0); @@ -636,6 +648,18 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho setIsSelecting(false); setIndicatedSystem(null); downClientPointRef.current = null; + mouseButtonRef.current = null; + return; + } + + // Ignore non-left button for selection commit + if (mouseButtonRef.current !== 0) { + clearSelectTimer(); + setIsPanning(false); + setIsSelecting(false); + setIndicatedSystem(null); + downClientPointRef.current = null; + mouseButtonRef.current = null; return; } @@ -643,6 +667,7 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho if (isPanning) { setIsPanning(false); + mouseButtonRef.current = null; return; } @@ -661,6 +686,7 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho setIsSelecting(false); setIndicatedSystem(null); downClientPointRef.current = null; + mouseButtonRef.current = null; }, [draggingNode, isPanning, indicatedSystem, positions, systems, shiftSelecting, commitShiftSelection]); const handleWheel = useCallback((e: React.WheelEvent) => { @@ -832,7 +858,7 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho useEffect(() => { const onWindowMouseUp = () => { // if shift selection ongoing, commit on global mouseup as well - if (shiftSelecting) { + if (shiftSelecting && mouseButtonRef.current === 0) { commitShiftSelection(); } clearSelectTimer(); @@ -843,6 +869,7 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho setShiftCenter(null); setShiftRadius(0); downClientPointRef.current = null; + mouseButtonRef.current = null; }; window.addEventListener('mouseup', onWindowMouseUp); return () => window.removeEventListener('mouseup', onWindowMouseUp);