fix: sweep select stale closure + add sweepSelectRef
handleMouseUp captured stale sweepSelect state from render closure. Added sweepSelectRef updated on every mousemove so mouseup reads the latest sweep range correctly.
This commit is contained in:
+10
-3
@@ -6921,6 +6921,7 @@ const App = () => {
|
||||
const isSweepingRef = useRef(false);
|
||||
const sweepStartRef = useRef(0);
|
||||
const sweepTrackIdRef = useRef(null);
|
||||
const sweepSelectRef = useRef(null);
|
||||
const [localSelectionTrackId, setLocalSelectionTrackId] = useState(null);
|
||||
const [localSelectionStart, setLocalSelectionStart] = useState(null);
|
||||
const [localSelectionEnd, setLocalSelectionEnd] = useState(null);
|
||||
@@ -11624,7 +11625,9 @@ const App = () => {
|
||||
isSweepingRef.current = true;
|
||||
sweepStartRef.current = startTime;
|
||||
sweepTrackIdRef.current = trackId;
|
||||
setSweepSelect({ startTime, endTime: startTime });
|
||||
var init = { startTime, endTime: startTime };
|
||||
sweepSelectRef.current = init;
|
||||
setSweepSelect(init);
|
||||
setSelectedItemIds(new Set());
|
||||
};
|
||||
|
||||
@@ -11890,12 +11893,16 @@ const App = () => {
|
||||
const scrollLeft = wrapper.scrollLeft;
|
||||
const mouseX = e.clientX - rect.left + scrollLeft;
|
||||
const time = Math.max(0, mouseX / zoom - leadInMarginRef.current);
|
||||
setSweepSelect(prev => prev ? { ...prev, endTime: time } : null);
|
||||
setSweepSelect(prev => {
|
||||
var updated = prev ? { ...prev, endTime: time } : null;
|
||||
sweepSelectRef.current = updated;
|
||||
return updated;
|
||||
});
|
||||
};
|
||||
const handleMouseUp = () => {
|
||||
if (!isSweepingRef.current) return;
|
||||
isSweepingRef.current = false;
|
||||
const sweep = sweepSelect;
|
||||
const sweep = sweepSelectRef.current;
|
||||
if (sweep && sweepTrackIdRef.current) {
|
||||
const tId = sweepTrackIdRef.current;
|
||||
const start = Math.min(sweep.startTime, sweep.endTime);
|
||||
|
||||
Reference in New Issue
Block a user