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:
@@ -0,0 +1,28 @@
|
||||
// UndoEntry.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/// One entry on an ``UndoCoordinator`` undo or redo stack.
|
||||
///
|
||||
/// Structural edits (adding, removing, moving, or re-routing pedals and boards) are captured as a
|
||||
/// whole-rig ``ShoeGazeState`` snapshot. Undo and redo are a symmetric swap: applying an entry
|
||||
/// restores its snapshot and pushes the pre-restore state onto the opposite stack.
|
||||
enum UndoEntry {
|
||||
|
||||
/// A whole-rig topology change — adding, removing, or moving a pedal, board, split/merge region,
|
||||
/// or router. The associated ``ShoeGazeState`` is the snapshot to restore when this entry is
|
||||
/// applied: the rig state *before* the change for an undo entry, or *after* it for the matching
|
||||
/// redo entry.
|
||||
case structural(label: String, state: ShoeGazeState)
|
||||
|
||||
/// A human-readable description of the action (e.g. `"Add Reverb"`), shown next to the Undo /
|
||||
/// Redo menu items and toolbar buttons.
|
||||
var label: String {
|
||||
switch self {
|
||||
case .structural(let label, _):
|
||||
return label
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user