fix: group drag moves all items, clamp to track 0, auto-add track
Restore multiIds cross-track move for all selected items. Clamp targetTrackId to first track. Auto-add new track via addNewTrack() when dragging below the last track.
This commit is contained in:
+17
-7
@@ -12049,7 +12049,21 @@ const App = () => {
|
||||
wrapper.scrollLeft = Math.max(0, itemPx - keepMargin);
|
||||
setCanvasRedrawCount(n => n + 1);
|
||||
}
|
||||
const targetTrackId = hoveredTrackIdRef.current || drag.trackId;
|
||||
var allTrksNow = activeTracksRef.current || [];
|
||||
var targetTrackId = hoveredTrackIdRef.current || drag.trackId;
|
||||
// Clamp to min track 0 (first track)
|
||||
var trkIds = allTrksNow.map(function(x) { return x.id; });
|
||||
var targetIdx = trkIds.indexOf(targetTrackId);
|
||||
if (targetIdx < 0 && allTrksNow.length > 0) targetTrackId = allTrksNow[0].id;
|
||||
// Auto-add track when dragging below the last track
|
||||
if (targetIdx < 0 || targetIdx >= allTrksNow.length - 1) {
|
||||
var isBelow = e.clientY > rect.top + rect.height;
|
||||
if (isBelow) {
|
||||
addNewTrack();
|
||||
var newTrks = activeTracksRef.current || [];
|
||||
targetTrackId = newTrks[newTrks.length - 1].id;
|
||||
}
|
||||
}
|
||||
updateActiveTracks(prev => {
|
||||
let movedItem = null;
|
||||
for (let track of prev) {
|
||||
@@ -12084,12 +12098,10 @@ const App = () => {
|
||||
Object.keys(drag.multiIds).forEach(function(mid) {
|
||||
var info = drag.multiIds[mid];
|
||||
var newVal = info.start + delta;
|
||||
var isDraggedItem = mid === drag.itemId;
|
||||
var currentTid = currentTrackMap.hasOwnProperty(mid) ? currentTrackMap[mid] : info.trackId;
|
||||
var onCurrentTrack = currentTid === t.id;
|
||||
if (onCurrentTrack) {
|
||||
if (!crossTracks || (isDraggedItem && t.id === targetTrackId) || (!isDraggedItem && t.id === currentTid)) {
|
||||
// Update position in-place (same track or non-dragged items stay)
|
||||
if (!crossTracks || t.id === targetTrackId) {
|
||||
if (info.type === 'section') {
|
||||
var idx = resultSections.findIndex(function(s) { return s.id === mid; });
|
||||
if (idx >= 0) resultSections[idx] = { ...resultSections[idx], start: Math.max(0, newVal) };
|
||||
@@ -12101,13 +12113,11 @@ const App = () => {
|
||||
if (idx >= 0) resultClips[idx] = { ...resultClips[idx], startTime: Math.max(0, newVal) };
|
||||
}
|
||||
} else {
|
||||
// Dragged item leaves this track
|
||||
if (info.type === 'section') resultSections = resultSections.filter(function(s) { return s.id !== mid; });
|
||||
else if (info.type === 'midiItem') resultMidis = resultMidis.filter(function(mx) { return mx.id !== mid; });
|
||||
else if (info.type === 'clip') { var cid3 = 'default_' + t.id; resultClips = resultClips.filter(function(cx) { return cx.id !== mid && cx.id !== cid3; }); }
|
||||
}
|
||||
} else if (isDraggedItem && crossTracks && t.id === targetTrackId) {
|
||||
// Only the dragged item can cross tracks — insert on target
|
||||
} else if (crossTracks && t.id === targetTrackId) {
|
||||
var srcItem = null;
|
||||
for (var pi2 = 0; pi2 < prev.length; pi2++) {
|
||||
var tr2 = prev[pi2];
|
||||
|
||||
Reference in New Issue
Block a user