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:
2026-07-27 21:51:53 +07:00
parent fd24c2dcd8
commit b8dfc9b211
2 changed files with 13 additions and 6 deletions
+10 -3
View File
@@ -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);