FIX: sửa lỗi undo khi move items, lỗi undo khi duplication item
This commit is contained in:
+24
-31
@@ -9132,37 +9132,23 @@ const App = () => {
|
||||
showToast(`Redo: ${last.action_type}`, 'info');
|
||||
};
|
||||
const applyTrackState = (trackId, state) => {
|
||||
if (trackId === 'ALL_TRACKS') {
|
||||
state.forEach(entry => {
|
||||
applyTrackState(entry.trackId, entry.state);
|
||||
});
|
||||
return;
|
||||
}
|
||||
updateActiveTracks(prev => prev.map(t => {
|
||||
if (t.id !== trackId) return t;
|
||||
var updated = { ...t, ...state };
|
||||
if (state.sections) {
|
||||
updated.sections = t.sections ? t.sections.map(function(s) {
|
||||
var match = state.sections.find(function(ss) { return ss.id === s.id; });
|
||||
return match ? { ...s, start: match.start, duration: match.duration } : s;
|
||||
}) : state.sections;
|
||||
state.sections.forEach(function(ss) {
|
||||
if (!updated.sections.find(function(s) { return s.id === ss.id; })) {
|
||||
updated.sections.push(ss);
|
||||
}
|
||||
});
|
||||
if (state.sections !== undefined) {
|
||||
updated.sections = state.sections;
|
||||
}
|
||||
if (state.midiItems) {
|
||||
updated.midiItems = t.midiItems ? t.midiItems.map(function(m) {
|
||||
var match = state.midiItems.find(function(sm) { return sm.id === m.id; });
|
||||
return match ? { ...m, startTime: match.startTime, duration: match.duration } : m;
|
||||
}) : state.midiItems;
|
||||
state.midiItems.forEach(function(sm) {
|
||||
if (!updated.midiItems.find(function(m) { return m.id === sm.id; })) {
|
||||
updated.midiItems.push(sm);
|
||||
}
|
||||
});
|
||||
if (state.midiItems !== undefined) {
|
||||
updated.midiItems = state.midiItems;
|
||||
}
|
||||
if (state.clips) {
|
||||
updated.clips = t.clips ? t.clips.map(function(c) {
|
||||
var cid = c.id === 'default' ? 'default_' + t.id : c.id;
|
||||
var match = state.clips.find(function(sc) { return sc.id === cid; });
|
||||
return match ? { ...c, startTime: match.startTime } : c;
|
||||
}) : state.clips;
|
||||
if (state.clips !== undefined) {
|
||||
updated.clips = state.clips;
|
||||
}
|
||||
return updated;
|
||||
}));
|
||||
@@ -9198,6 +9184,13 @@ const App = () => {
|
||||
midiItems: track.midiItems ? track.midiItems.map(function(m) { return { id: m.id, startTime: m.startTime, duration: m.duration, name: m.name, notes: m.notes ? m.notes.map(function(n) { return { id: n.id, pitch: n.pitch, start_beat: n.start_beat, duration_beats: n.duration_beats, velocity: n.velocity }; }) : null }; }) : null
|
||||
};
|
||||
};
|
||||
const captureAllTracksSnapshot = () => {
|
||||
const curTracks = activeTracksRef.current || activeTracks || [];
|
||||
return curTracks.map(t => ({
|
||||
trackId: t.id,
|
||||
state: captureTrackSnapshot(t.id)
|
||||
}));
|
||||
};
|
||||
|
||||
const setBpmWithUndo = (newBpm) => {
|
||||
const oldBpm = bpmRef.current;
|
||||
@@ -14105,7 +14098,7 @@ const App = () => {
|
||||
if (!track) return;
|
||||
if (multiIds) {
|
||||
var newOriginals = {};
|
||||
var dupBeforeSnap = captureTrackSnapshot(trackId);
|
||||
var dupBeforeSnap = captureAllTracksSnapshot();
|
||||
updateActiveTracks(function(prev) {
|
||||
return prev.map(function(t) {
|
||||
var updatedSections = t.sections ? t.sections.slice() : [];
|
||||
@@ -14148,7 +14141,7 @@ const App = () => {
|
||||
if (!item) return;
|
||||
var rearrangeNewId = itemType + '_dup_' + Date.now();
|
||||
var newItem = { ...item, id: rearrangeNewId, name: item.name + ' (Copy)' };
|
||||
var singleDupBeforeSnap = captureTrackSnapshot(trackId);
|
||||
var singleDupBeforeSnap = captureAllTracksSnapshot();
|
||||
updateActiveTracks(function(prev) {
|
||||
return prev.map(function(t) {
|
||||
if (t.id !== trackId) return t;
|
||||
@@ -14163,7 +14156,7 @@ const App = () => {
|
||||
var its = itemType === 'section' ? (curTrk?.sections || []) : (curTrk?.midiItems || []);
|
||||
var it = its.find(function(x) { return x.id === itemId; });
|
||||
var origPos = it ? (itemType === 'section' ? it.start : it.startTime) : 0;
|
||||
var beforeSnap = captureTrackSnapshot(trackId);
|
||||
var beforeSnap = captureAllTracksSnapshot();
|
||||
setDraggedSectionItem({ trackId, itemType, itemId, clickOffset, multiIds, originalPositions: { [itemId]: origPos }, beforeSnap });
|
||||
}
|
||||
};
|
||||
@@ -14349,8 +14342,8 @@ const App = () => {
|
||||
});
|
||||
});
|
||||
if (changed || drag.beforeSnap) {
|
||||
var afterSnap = captureTrackSnapshot(trackId);
|
||||
pushAction('MOVE_ITEM', trackId, drag.beforeSnap || beforeSnap, afterSnap);
|
||||
var afterSnap = captureAllTracksSnapshot();
|
||||
pushAction('MOVE_ITEM', 'ALL_TRACKS', drag.beforeSnap || beforeSnap, afterSnap);
|
||||
}
|
||||
if (drag.itemType === 'midiItem') {
|
||||
let finalTrackId = null;
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user