Review fixes: reindex activeBoardIndex; safer live-input rebuild

- moveBoard/removeBoard now keep activeBoardIndex pointing at the soloed board
  (track by identity on move; shift down or clear on remove), so the Solo
  highlight no longer lights the wrong cell after reorder or delete.
- rebuildWithLiveInput snapshots the rig before any teardown and aborts if the
  snapshot fails, instead of tearing down then seeding a fallback (no silent
  rig loss). The engine-already-has-input early return now also persists the
  live-input selection, via a shared selectLiveInputAndPersist helper.
- Test: activeBoardIndex tracks reorder and removal.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-23 21:22:44 -07:00
parent 652a5a76ca
commit 6ad813601f
3 changed files with 84 additions and 12 deletions
+17
View File
@@ -345,6 +345,16 @@ public final class ShoeGaze {
// Remove the pedals and release the board's buses.
board.teardown()
boards.remove(at: index)
// Keep the soloed-board index valid: clear it if the soloed board was removed,
// otherwise shift it down when a board before it was removed.
if let active: Int = activeBoardIndex {
if active == index {
activeBoardIndex = nil
} else if active > index {
activeBoardIndex = active - 1
}
}
}
// MARK: - Chain router
@@ -395,9 +405,16 @@ public final class ShoeGaze {
/// so it is always a valid insertion point.
public func moveBoard(_ board: PedalBoard, to index: Int) {
guard let sourceIndex: Int = boards.firstIndex(where: { $0 === board }) else { return }
// Track the soloed board by identity so its index follows the reorder.
let soloedBoard: PedalBoard? = activeBoardIndex.flatMap { idx in
idx < boards.count ? boards[idx] : nil
}
let removed: PedalBoard = boards.remove(at: sourceIndex)
let destination: Int = min(index, boards.count)
boards.insert(removed, at: destination)
if let soloedBoard {
activeBoardIndex = boards.firstIndex(where: { $0 === soloedBoard })
}
}
// MARK: - Teardown