fix: pending drag effect calls stale handleSectionItemDragStart

The useEffect with [] deps captured handleSectionItemDragStart
from initial render, which read an empty selectedItemIds.
Added handleSectionItemDragStartRef that stays current across
renders; the effect calls ref.current instead of the closure.
This commit is contained in:
2026-07-27 22:21:17 +07:00
parent c99527e687
commit 74fdc2b303
2 changed files with 6 additions and 4 deletions
+3 -1
View File
@@ -6948,6 +6948,7 @@ const App = () => {
const sweepTrackIdRef = useRef(null);
const sweepSelectRef = useRef(null);
const pendingDragRef = useRef(null); // { trackId, itemType, itemId, clickOffset, startX, startY }
const handleSectionItemDragStartRef = useRef(null);
const [localSelectionTrackId, setLocalSelectionTrackId] = useState(null);
const [localSelectionStart, setLocalSelectionStart] = useState(null);
const [localSelectionEnd, setLocalSelectionEnd] = useState(null);
@@ -11758,6 +11759,7 @@ const App = () => {
}
setDraggedSectionItem({ trackId, itemType, itemId, clickOffset, multiIds });
};
handleSectionItemDragStartRef.current = handleSectionItemDragStart;
// Section / MIDI Item Resize Start
const handleSectionItemResizeStart = (trackId, itemType, itemId, side, clickTime) => {
@@ -11875,7 +11877,7 @@ const App = () => {
var dx = e.clientX - pd.startX;
if (Math.abs(dx) > 5) {
pendingDragRef.current = null;
handleSectionItemDragStart(pd.trackId, pd.itemType, pd.itemId, pd.clickOffset, true);
if (handleSectionItemDragStartRef.current) handleSectionItemDragStartRef.current(pd.trackId, pd.itemType, pd.itemId, pd.clickOffset, true);
}
};
document.addEventListener('mousemove', handleMouseMove);