feat(undo): multi-level structural undo/redo for rig edits
Add UndoCoordinator: 50-deep undo/redo of structural edits (add/insert/ remove/move pedals in any lane, stereo-split/parallel/merge/unzip routing, add/remove/move boards, Clear Board). Each edit records a named checkpoint via a perform(label:) wrapper threaded through the builder, board-flow, board-bar, and boards-sheet views (injected through the SwiftUI environment, re-injected onto the boards sheet). Restore is surgical, not a whole-rig reload: it reconciles board-by-board (remove added / re-add removed / rebuild changed / reorder) using the same per-board rebuild path as an ordinary edit, so undo never tears the rig down — recording, looper buffers, other boards' reverb/delay tails, and bypass/solo state all survive. It also merges live parameter values by pedal id, so undoing a topology edit never reverts a knob turned afterwards; a pedal the edit removed returns with its snapshot values. No-op edits record nothing (compared via hasSameRigContent). History clears on rig load / new / switch. UI: macOS Edit menu (Undo ⌘Z / Redo ⇧⌘Z with dynamic "Undo <action>" titles, deferring to a text field's own editor while typing); iOS visible ↶/↷ buttons + ⌘Z/⇧⌘Z. Rig mute moves from ⌘Z to ⌘M. Help text updated. Fix: every pedal edit rebuilt the board via BoardState(label:segments:) without id:, regenerating the board UUID and breaking MIDI board bindings after any edit. Thread id: board.id through all 10 rebuild sites; add editingPreservesBoardIdentity regression test. Tests: 12 UndoCoordinator tests (restore correctness, param preservation, untouched-board identity, multi-board re-add, depth cap, no-op, throwing action). Full suite 830 green; both demo schemes build (macOS + iPad). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -56,7 +56,7 @@ extension ShoeGaze {
|
||||
branch.append(newState)
|
||||
}
|
||||
}
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
return try rebuildBoard(board, from: BoardState(id: board.id, label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
/// Inserts a pedal of the given type at `index` within a lane, shifting later pedals along.
|
||||
@@ -117,7 +117,7 @@ extension ShoeGaze {
|
||||
branch.insert(newState, at: index)
|
||||
}
|
||||
}
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
return try rebuildBoard(board, from: BoardState(id: board.id, label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
/// Removes the pedal at `index` within a lane.
|
||||
@@ -149,7 +149,7 @@ extension ShoeGaze {
|
||||
branch.remove(at: index)
|
||||
}
|
||||
}
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
return try rebuildBoard(board, from: BoardState(id: board.id, label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
/// Moves the pedal at `sourceIndex` to `destinationIndex` within a lane.
|
||||
@@ -175,7 +175,7 @@ extension ShoeGaze {
|
||||
try Self.moveWithinArray(&branch, from: sourceIndex, to: destinationIndex)
|
||||
}
|
||||
}
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
return try rebuildBoard(board, from: BoardState(id: board.id, label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
/// Moves a pedal from one lane to another (e.g. the main chain into a stereo-unzip lane, or
|
||||
@@ -252,7 +252,7 @@ extension ShoeGaze {
|
||||
}
|
||||
}
|
||||
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
return try rebuildBoard(board, from: BoardState(id: board.id, label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
// MARK: - Branch regions
|
||||
@@ -270,7 +270,7 @@ extension ShoeGaze {
|
||||
guard board.width == 1 else { throw ShoeGazeError.cannotSplitStereoChain }
|
||||
var segments: [BoardSegmentState] = board.captureState().segments
|
||||
segments.append(.stereoSplit(StereoSplitState(left: [], right: [], route: .stereo)))
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
return try rebuildBoard(board, from: BoardState(id: board.id, label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
/// Inserts an empty stereo-unzip region immediately after the segment at `topLevelIndex`,
|
||||
@@ -297,7 +297,7 @@ extension ShoeGaze {
|
||||
.stereoUnzip(StereoUnzipState(left: [], right: [], route: .stereo)),
|
||||
at: topLevelIndex + 1
|
||||
)
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
return try rebuildBoard(board, from: BoardState(id: board.id, label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
/// Returns `true` when the segment immediately after `topLevelIndex` is a stereo-unzip region —
|
||||
@@ -318,7 +318,7 @@ extension ShoeGaze {
|
||||
public func appendParallelSplit(to board: PedalBoard) throws -> PedalBoard {
|
||||
var segments: [BoardSegmentState] = board.captureState().segments
|
||||
segments.append(.parallel(ParallelSectionState(branchA: [], branchB: [], mode: .both)))
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
return try rebuildBoard(board, from: BoardState(id: board.id, label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
/// Appends a merge-to-mono node, collapsing a stereo tail back to mono.
|
||||
@@ -330,7 +330,7 @@ extension ShoeGaze {
|
||||
guard board.width == 2 else { throw ShoeGazeError.cannotMergeMonoChain }
|
||||
var segments: [BoardSegmentState] = board.captureState().segments
|
||||
segments.append(.mergeToMono)
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
return try rebuildBoard(board, from: BoardState(id: board.id, label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
/// Removes the top-level segment (a linear pedal, a split region, or a merge node) at
|
||||
@@ -345,7 +345,7 @@ extension ShoeGaze {
|
||||
throw ShoeGazeError.pedalIndexOutOfRange(index: topLevelIndex, count: segments.count)
|
||||
}
|
||||
segments.remove(at: topLevelIndex)
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
return try rebuildBoard(board, from: BoardState(id: board.id, label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
// MARK: - Input source switching
|
||||
|
||||
Reference in New Issue
Block a user