diff --git a/src/components/DimensionsView.tsx b/src/components/DimensionsView.tsx index 27f0546..5727cb0 100644 --- a/src/components/DimensionsView.tsx +++ b/src/components/DimensionsView.tsx @@ -66,42 +66,6 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat const hoveredIndexRef = React.useRef(null); const activeClusterKeyRef = React.useRef(null); - React.useEffect(() => { - const handleGlobalMouseUp = () => { - if (isDraggingRef.current && activeClusterKeyRef.current) { - const clusterKey = activeClusterKeyRef.current; - const start = dragStartRef.current; - const end = hoveredIndexRef.current; - - if (start !== null && end !== null) { - const cluster = nearDuplicateClusters.find(c => c.groups[0].key === clusterKey); - if (cluster) { - const allClusterRows = cluster.groups.flatMap(g => g.rows); - const s = Math.min(start, end); - const e = Math.max(start, end); - const indicesToSelect = allClusterRows.slice(s, e + 1).map(r => r.index); - - setClusterSelections(prev => { - const next = new Set(prev[clusterKey] ?? []); - indicesToSelect.forEach(idx => next.add(idx)); - return { ...prev, [clusterKey]: next }; - }); - } - } - } - isDraggingRef.current = false; - dragStartRef.current = null; - hoveredIndexRef.current = null; - activeClusterKeyRef.current = null; - setIsDragging(false); - setDragStart(null); - setHoveredIndex(null); - setActiveClusterKey(null); - }; - - window.addEventListener('mouseup', handleGlobalMouseUp); - return () => window.removeEventListener('mouseup', handleGlobalMouseUp); - }, [nearDuplicateClusters]); const groups = useMemo(() => { const groupMap = new Map(); @@ -252,6 +216,43 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat return clusters; }, [groups]); + React.useEffect(() => { + const handleGlobalMouseUp = () => { + if (isDraggingRef.current && activeClusterKeyRef.current) { + const clusterKey = activeClusterKeyRef.current; + const start = dragStartRef.current; + const end = hoveredIndexRef.current; + + if (start !== null && end !== null) { + const cluster = nearDuplicateClusters.find(c => c.groups[0].key === clusterKey); + if (cluster) { + const allClusterRows = cluster.groups.flatMap(g => g.rows); + const s = Math.min(start, end); + const e = Math.max(start, end); + const indicesToSelect = allClusterRows.slice(s, e + 1).map(r => r.index); + + setClusterSelections(prev => { + const next = new Set(prev[clusterKey] ?? []); + indicesToSelect.forEach(idx => next.add(idx)); + return { ...prev, [clusterKey]: next }; + }); + } + } + } + isDraggingRef.current = false; + dragStartRef.current = null; + hoveredIndexRef.current = null; + activeClusterKeyRef.current = null; + setIsDragging(false); + setDragStart(null); + setHoveredIndex(null); + setActiveClusterKey(null); + }; + + window.addEventListener('mouseup', handleGlobalMouseUp); + return () => window.removeEventListener('mouseup', handleGlobalMouseUp); + }, [nearDuplicateClusters]); + const toggleGroup = (key: string) => { const next = new Set(expandedGroups); if (next.has(key)) {