fix(RegionMap.tsx): restrict map interactions to left mouse button for consistency

This commit is contained in:
2025-08-11 19:32:20 +02:00
parent 3a4e30d372
commit 3b20e07b17

View File

@@ -119,6 +119,7 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
const [indicatedSystem, setIndicatedSystem] = useState<string | null>(null);
const selectTimerRef = useRef<number | null>(null);
const downClientPointRef = useRef<{ x: number; y: number } | null>(null);
const mouseButtonRef = useRef<number | null>(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) {
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);